QAbstractListModel dataChanged() refresh not working in QML

  • In my 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 ?

  • @clogwog said:


    Can you show some your code of this class ? especially data changing part

  • @jalomic

    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;
    QDomNodeList nodes = doc.elementsByTagName("photo");

        for(int t=0; t < nodes.count(); t++ )
            QDomElement photo =;
           if( datavalidchecks )
                QString photoUrl = QString("").arg(photo.attribute("farm"),photo.attribute("server"),photo.attribute("id"),photo.attribute("secret"));
                TSImageData image1(QUrl(photoUrl) );
                if( photo.hasAttribute("title"))
        int end1 = image_list.count();
        emit dataChanged (index(0),index(end1 ));


  • found the answer here

    instead of calling
    emit dataChanged(...)

    i now use beginInsertRows and endInserRows and it all starts working.

    thanks @jalomic your question made me search more.

  • @clogwog As expected

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.