QAbstractListModel dataChanged() refresh not working in QML
Solved
QML and Qt Quick
-
In my main.cc i set a data-model to a
MyDataModel aDataModel; // MyDataModel is a subclass of QAbstractListModel ctxt->setContextProperty("aaModel", &aDataModel);
and in the QML i use it as the model like:
ListView { model: aaModel delegate: Item { ...
this works fine when the QML is initially loaded, but when the data is updated it doesn't get re-evaluated and i still see the old data until i pop out of the QML and re-load.
when the data gets updated in the model i emit dataChanged(..) without avail.
any tips on how i can get the refresh can happen ?
-
of coarse:
// called when a REST function returns actual data
void MyDataModel::recentPhotoRequestDone()
{
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
QByteArray data = reply->readAll();
QDomDocument doc;
doc.setContent(data);
QDomNodeList nodes = doc.elementsByTagName("photo");image_list.clear(); for(int t=0; t < nodes.count(); t++ ) { QDomElement photo = nodes.at(t).toElement(); if( datavalidchecks ) { QString photoUrl = QString("http://farm%1.staticflickr.com/%2/%3_%4_q.jpg").arg(photo.attribute("farm"),photo.attribute("server"),photo.attribute("id"),photo.attribute("secret")); TSImageData image1(QUrl(photoUrl) ); if( photo.hasAttribute("title")) image1.setName(photo.attribute("title")); image_list.append(image); } } int end1 = image_list.count(); emit dataChanged (index(0),index(end1 )); }
}