Reputation: 3760
{QML/Qt-5.2, Win7}
The usual way of accessing roles is using model.roleName
ListModel {
id: mod
ListElement { role0: "hello"; role1: "aaa" }
ListElement { role0: "helloThere"; role1: "bbb" }
}
//.....
Repeater {
model: mod
delegate: Text {//....
text: model.role0
}
}
If i require that i have a line-edit where i can type in a role to be considered during the runtime then the above way of accessing the roles at runtime fails. But this seems to be equivalent
Text {//...
text: model["role0"] //is this legal (it works btw) instead of model.role0 ?
}
Now it’s basically a string so i can dynamically input the role and the display would change according to the specified role. But this is not documented anywhere, just stumbled upon it. The question is if this (the second method) is a standard way to do it? Otherwise what is the way i can specify the role during the runtime ?
Upvotes: 1
Views: 360
Reputation: 98495
The expression that you write is in javascript, and in javascript model.foo
and model["foo"]
are functionally equivalent. Don't forget that you have the power of javascript available to you :)
Upvotes: 2