Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.0.0
-
None
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() } } }