I made a class derived from QAbstractListModel
and re-implemented all the necessary functions. I create an object of it, fill in some initial data into the model (all beginInsertRows etc done) and then pass it (the object) to qml via setContextProperty
. I'm using QQuickView
. Once qml is shown by show()
command, I spawn a QThread
in which I use the pointer of the Model object. The thread keeps adding data to the model via direct call to Model's addData(..)
function (which has beginInsertRows
etc).
Problem: There is no update of the UI. I get the following listed in the Application Output pane in QtCreator:
QObject::connect: Cannot queue arguments of type 'QQmlChangeSet'
(Make sure 'QQmlChangeSet' is registered using qRegisterMetaType().)
The form here shows the exactly same problem but I can't use signal and slot as mentioned there.
EDIT:
Running addData() from main thread (using signal-slot as mentioned in the link but not subclassing QThread
) did update the ListView to the initial data but the view is not updated after dataChanged() signal. Let me explain it little bit more clearly.
/*This is the class in which data is stored*/
class ClientCardModel : public QAbstractListModel {
....
QList<ClientCard*> m_list;
};
...
ClientCardModel hand; // object to send to qml
...
// New worker thread created and all the following codes are exexuted in that
QThread *workerThread = new QThread;
/*New data is created to be inserted in model*/
ClientCard* ccard = new ClientCard; //New card with all initial values
hand.addData(ccard);
//Many more card are created and inserted
...
// Lots of coding takes place
/*
Other code
*/
...
UpdateFieldCard(ccard); //Function to update the values of ccard
emit hand.dataChanged(index(0), index(rowCount()-1));
...
/*workerThread is pauded using QWaitCondition*/
ListView in qml is showing only the initial data, i.e, initial data of ccard when it was inserted using addData(). ListView is not getting updated after emitting dataChanged() signal (actually sometimes during debugging the list get updated but the behaviour is unpredictable). Also QQmlChangeSet
error I was getting earlier is gone. Should there be some time difference between beginInsertRows()
and dataChanged()
? Whether I call dataChanged() from main thread or worker thread, it's not updating. Please give suggestions.