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

Clearing a VisualDataGroup following a model move() sometimes crashes VisualDataModel

    XMLWordPrintable

Details

    Description

      In the following code, a single list item can be selected at any time with a left mouse-click. When the space key is pressed, the selected item is moved to the bottom of the list, and the selection is cleared by clearing the relevant VisualDataGroup.

      The call to selectedGroup.remove() following the move() crashes if the second or third list item is moved. (The crash doesn't occur if remove() is called before move() instead.)

      import QtQuick 2.0
      
      Item {
          width: 800; height: 700
      
          ListView {
              id: a_view
              width: 240; height: 320
              x: 100; y: 100
              model: VisualDataModel {
                  groups: [
                      VisualDataGroup { id: selectedGroup; name: "selected" }
                  ]
                  model: ListModel {
                      id: a_model
                      ListElement { name: 'A' }
                      ListElement { name: 'B' }
                      ListElement { name: 'C' }
                      ListElement { name: 'D' }
                  }
                  delegate: Rectangle {
                      id: item
                      width: 100; height: 50; border.width: VisualDataModel.inSelected ? 2 : 1
                      Text { text: name }
                      MouseArea {
                          anchors.fill: parent
                          onClicked: {
                              selectedGroup.remove(0, selectedGroup.count)
                              item.VisualDataModel.inSelected = !item.VisualDataModel.inSelected
                          }
                      }
                  }
              }
          }
      
          focus: true
      
          Keys.onSpacePressed: {
              if (selectedGroup.count > 0) {
                  var selectedIndex = selectedGroup.get(0).itemsIndex
                  a_model.move(selectedIndex, a_model.count - 1, 1)
                  selectedGroup.remove(0, selectedGroup.count)    // crashes at QQuickVisualDataModelPrivate::itemsRemoved()
              }
          }
      
      }
      

      Attachments

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

        Activity

          People

            denexter Andrew den Exter (closed Nokia identity) (Inactive)
            bealam Bea Lam (closed Nokia identity) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes