Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-45500

QQuickListView keeps delegates around until next layout phase after model items have been removed

    XMLWordPrintable

Details

    • Shovelling Snow, Q1/2020 Finale, Q2/2020 kick off

    Description

      I implement a QAbstractItemModel subclass which returns QObject* a instance with properties.

      I implement QML code to consume the properties from the instance:

          ListView {
              delegate: Item {
                  id: deleg
                  property var obj: model.instance
                      Text {
                          text: deleg.obj.name
                      }
                      // ...
      

      I implement a method to delete an item.

              beginRemoveRows(QModelIndex(), i, i);
              m_instances.at(i)->deleteLater();
              m_instances.removeAt(i);
              endRemoveRows();
      

      When it is invoked I get warnings from QML

      main.qml:29: TypeError: Cannot read property 'colorName' of null
      main.qml:24: TypeError: Cannot read property 'name' of null
      

      It seems that QML evaluates bindings in delegates whose model rows have already been deleted. It should probably not do that.

      Small testcase attached

      Attachments

        1. BindingIssue.zip
          2 kB
        2. testcase.zip
          2 kB

        Issue Links

          For Gerrit Dashboard: QTBUG-45500
          # Subject Branch Project Status CR V

          Activity

            People

              axelspoerl Axel Spoerl
              ske Steve
              Votes:
              34 Vote for this issue
              Watchers:
              33 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There is 1 open Gerrit change