Dynamically updating QML ListView
This post is deleted!
@RyonMS Can you use QStringListModel?
@Eeli-K I could, I was actually just looking at doing this. I'm new to the Qt framework and don't really know much about it.
@mrjj Hello and thanks for the welcome! I have read through that page, but I'm still a bit lost. I have a class that now contains a QStringListModel for the ListView in QML. I just still don't know how to hook this model up to the QML.
@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.
If you still doubt ask me.! welcome.
@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());
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!