A ListModel not parsed as typical QML, but uses a custom parser to process ListElement declarations. This allows the model to avoid creating expensive objects for each data item. ListModel has a number of functions available for managing model data through QML. You can add your own functions to the model in QML, which you can access with C ++, for example.
ListModel { id:myListModel objectName: "model" function setColor(index, color) { myListModel.setProperty(index, "color", color) } ListElement {name:"one";color:"red"} ListElement {name:"two";color:"green"} }
and in C ++:
QObject* o=ui->declarativeView->rootObject()->findChild<QObject*>("model"); QMetaObject::invokeMethod(o, "setColor", Q_ARG(QVariant, 0), Q_ARG(QVariant, "yellow"));
source share