Index undefined for elements in ObjectModel?
-
according to Qt document http://qt-project.org/doc/qt-5/qml-qtqml-models-objectmodel.html#index-prop
An item can determine its index within the model via the index attached property.
my object model code:
@ ObjectModel {
id: itemModelRectangle { width: view.width; height: view.height color: "#FFFEF0" Text { text: "Page 1"; font.bold: true; anchors.centerIn: parent } Component.onDestruction: if (printDestruction) print("destroyed 1") } Rectangle { width: view.width; height: view.height color: "#F0FFF7" Text { text: "Page 2"; font.bold: true; anchors.centerIn: parent } Component.onDestruction: if (printDestruction) print("destroyed 2") } Rectangle { width: view.width; height: view.height color: view.currentIndex == index ? "blue" : "white" Text { text: "Page 3"; font.bold: true; anchors.centerIn: parent } Component.onDestruction: if (printDestruction) print("destroyed 3") }@
but when I ran, I saw this:
qrc:///main.qml:30: ReferenceError: index is not defined
what's the problem?
-
Looks like a bug to me. The count property works but not the index.
-
Did you try with itemModel.index ?
-
That too doesn't work.