Dynamically updating QML ListView
-
@RyonMS
Hi and welcome
I assume you did stumble upon
http://doc.qt.io/qt-5/model-view-programming.html -
@RyonMS : You can create a property of QStringList from your cpp class. And then create a instance of the class register it with QML.
Please refer below thread in which I created a sample code.
https://forum.qt.io/topic/76845/how-to-get-a-listmodel-to-update-from-a-signal/2
If you still doubt ask me.! welcome.
Regards,
Rajeesh Raveendran -
@RyonMS See also http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html. There you can see some options and examples. You can use QStringList as a model but it doesn't update automatically, but
"Note: There is no way for the view to know that the contents of a QStringList have changed. If the QStringList changes, it will be necessary to reset the model by calling QQmlContext::setContextProperty() again."
I didn't get it working even with setContextProperty(), however.
QStringListModel is a QAbstractItemModel subclass.
-
Dear @RyonMS ,
Have a look at "AbstractItemModel Example " in addAnimal function it uses
beginInsertRows(QModelIndex(), rowCount(), rowCount());
and
endInsertRows();
Also I implement my own subclass of QAbstractListModel and it works fine to me (dynamically update the values).
Of course you can change your model from QStringList to QList<Qstring> to become more similar to the example.I hope this may help you
-
@RajeeshRaveendran Using your example I think I have it working now! Really appreciate your help!