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

ListView does not refresh items that follow an item that has been deleted from the list model. It appears to make the ListView/ListModel unusable for dynamic data.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.0.0
    • 4.7.3
    • None
    • Windows 7, Qt Creator 2.2.0, QML Viewer using Qt 4.7.3

    Description

      I'm trying to use the ListModel to display dynamic data in a ListView. I get into siturations where the ListView will not display all changes made to the data until the user scrolls (flicks) the effected items off the screen and then back onto the screen.

      Example:

      The following qml has 3 buttons.

      1. Button one appends an asterisk to each item in the list.
      2. Button two adds a new item to the end of the list.
      3. Button three deletes the 2nd item in the list.

      Using the qml below, Try the following sequence of clicks:

      button 1, button 2, button 3, button 1

      Notice that with the second button 1 click, an asterisk only gets added to the first button in the list.

      Now try the following

      button 2, button 1

      Notice that every item except the second item gets an additional asterisk added.

      Any idea as to what could be going on?

      import QtQuick 1.0
      Rectangle {
          width: 360
          height: 360
          ListModel {
              id: listInfo
              ListElement {
                  name: "A"
              }
              ListElement {
                  name: "B"
              }
              ListElement {
                  name: "C"
              }
          }
          ListView {
              id: dataList
              width:  200
              height: 200
              model: listInfo
              delegate:  Text {
                  text: name
                  font.pixelSize: 36
              }
          }
          Rectangle {
              color: "red"
              x: 200; y: 10
              width: 100; height: 50
              Text {
                  anchors.centerIn: parent
                  color: "white"
                  text: "add *"
              }
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      for (var i=0; i<listInfo.count; i++ )
                      {
                          listInfo.get(i).name += "*"
                      }
                  }
              }
          }
          Rectangle {
              color: "green"
              x: 200; y: 70
              width: 100; height: 50
              Text {
                  anchors.centerIn: parent
                  color: "white"
                  text: "new item"
              }
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      listInfo.append({"name": listInfo.count + 1})
                  }
              }
          }
          Rectangle {
              color: "blue"
              x: 200; y: 130
              width: 100; height: 50
              Text {
                  anchors.centerIn: parent
                  color: "white"
                  text: "delete 2nd item"
              }
              MouseArea {
                  anchors.fill: parent
                  onClicked: {
                      listInfo.remove(1)
                  }
              }
          }
      }
      

      Attachments

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

        Activity

          People

            denexter Andrew den Exter (closed Nokia identity) (Inactive)
            johnm John McDaniel
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes