I want to populate a QComboBox defined in QML from my C++ code. I have seen two possible ways to do this:
QStringList
for example) from the C++ code, and expose it as Q_ELEMENT
. Then access that list from the C++, by saying model: backend.qlist
assuming the list is defined in backend
. Orview.rootObject()->findChild()
. Then use addItem()
to populate the list.What is best practice?
By far the first option!
QML stands for Qt Modeling Language, following the model-view architecture, in which the model (here C++) should not know anything about the view (QML).