ListModel elements with undefined properties
-
Hello.
In this example property 'a' is inverted when list element clicked. But after inserting first element (pressing 1) which has no 'a' property second element stops working and is not changed when clicked.
If instead append same element in the end of the list (press 2), all is ok. So inserting element with undefined properties brakes only elements after it. Elements before it are not affected.
If I use setProperty than all is ok.It seems properties are actually changed inside the model but are not updated on the view.
Is it legal to insert partially defined elements? If yes is it a bug?
@import QtQuick 1.1
ListView {
width: 200; height: 300focus: true Keys.onDigit1Pressed: listModel.insert(0, {}) Keys.onDigit2Pressed: listModel.insert(listModel.count, {}) model: ListModel { id: listModel ListElement { a: false } } delegate: Text { text: "a: " + a MouseArea { anchors.fill: parent onClicked: { var object = listModel.get(index) object.a = !object.a } } }
}@
-
I believe inserting partially defined elements is not legal, which means it could lead to pretty much any weird problems. All elements of a model should have the same set of roles defined.
-
Thanks for reply.
Why can't its have default values? My model has 20 roles. Only 6 of roles have sense for inserted item. I don't want to write all 20.
Documentation states that set of roles determined at first insertion. I can't find anything about requirements for further inserted objects. It was a hard to find bug.:)