Accessing model roles in qml
-
Hi,
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 ?