Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.2.1, 5.12.2
-
None
-
Ubuntu Trusty 14.04
Qt 5.2.1
Description
When you call listModel.remove(index) from within the delegate of a Repeater, and then try to access properties of either the item OR the surrounding context, QML throws a ReferenceError: not found.
This code worked in Qt 4.8.4 and I discovered it while porting.
The example below reproduces the problem.
import QtQuick 2.2 import QtQuick.Window 2.1 Window { id: root visible: true width: 360 height: 360 signal clicked(int index) onClicked: { console.log("clicked", index) } ListModel { id: myList ListElement { x: 1; y: 2 } ListElement { x: 1; y: 2 } ListElement { x: 1; y: 2 } ListElement { x: 1; y: 2 } } Repeater { anchors { left: parent.left top: parent.top margins: 20 } model: myList delegate: myDelegate } Component { id: myDelegate Rectangle { width: 100 height: 100 color: "green" MouseArea { anchors.fill: parent onClicked: { myList.remove(index) root.clicked(index) } } } } }
EXPECTED RESULT:
console displays
clicked -1
clicked -1
clicked -1
clicked -1
ACTUAL RESULT
console displays
qrc:/main.qml:44: ReferenceError: root is not defined
qrc:/main.qml:44: ReferenceError: root is not defined
qrc:/main.qml:44: ReferenceError: root is not defined
qrc:/main.qml:44: ReferenceError: root is not defined