So I had a fun problem with list models and delegates.
ListView{
....
delegate: Component {
Text{
text: data
}
}
}
...
ListModel {
id: captureModel
}
...
function updateList() {
...
for (var i = 0; i < list.rows.length; ++i) {
captureModel.append({"data": list.rows.item(i).data});
}
}
When I tried to append new elemets to the list model I got this error: "Unable to assign QQmlListReference to QString." I finally figured out that the problem was that my list element was called data. I just named it something else and it worked just fine. I thought the problem was that "data" was a reserved word, but I couldn't find it in either Javascript or QML lists. Though I couldn't find an official qml reserved word list. So do you guys know of a more complete list? I will like to avoid finding reserved words like this again or if the issue is actually something else I will like to hear the answer for that.
These are the lists that I was looking at:
https://www.w3schools.com/js/js_reserved.asp (Javascript).
Thanks in advance!!
You are right that your problem is because your list element role is called data
.
The underlying problem is that when you do text: data
you are accessing the data
property of your Text item. Your model data is shadowed by the property.
To be on the safe side, prefix your access to your roles with model
to avoid a naming clash with your delegate properties. In your case it will be text: model.data
.
data
is not a reserved keyword, it just happens to be the name of one of your delegate's properties.