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

Repeater delegates are not destroyed if the model is updated before completion

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.2, 6.5.0
    • Quick: Other
    • None
    • Linux/X11, Windows

    Description

      The Repeater item seems to behave weirdly when the model is updated (item added) in the Component.onCompleted of one of the delegates.

      In such a case, delegates are later not destoryed when items are removed from the model, even though the Repeater itself is updated ( count changed, itemsRemoved signal sent, index of delegate is set to -1).

      Note: is seems to work fine for ListView.

      Minimal example:

      ListModel {
          id: itemsModel
      }
      Button {
          anchors {
              top: parent.top
              right: parent.right
          }
          text: "Add first item"
          onClicked: {
              itemsModel.append({ "first": true });
          }
      }
      
      Repeater {
          model: itemsModel
      
          delegate: Rectangle {
              width: 100
              height: 100
              color: model.first ? "red" : "green"
      
              Component.onCompleted: {
                  x = (index + 1) * 20;
                  y = (index + 1) * 20;
                  z = index;
      
                  if (model.first === true) {
                      // uncomment the lines to make it working
                      //  Qt.callLater(() => {            
                      itemsModel.append({ "first": false });
                      //    });
                  }
              }
      
              Text {
                  text: index
              }
      
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      itemsModel.remove(index);
                  }
              }
          }
      }

      Examples:

      Delayed model update (working):

      Instant model update (not working - bug):

      Attachments

        1. not-working.gif
          not-working.gif
          12 kB
        2. working.gif
          working.gif
          12 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            justynah Justyna Hudziak
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes