[Development] Namespacing QML context properties
Alberto Mardegan
mardy at users.sourceforge.net
Sun Dec 8 14:38:58 CET 2013
Hi all!
One of the issues that has most bothered me when developing in QML is
dealing with the same variable name in item properties and context
properties. For example:
// "model" is a context property
Loader {
property variant model: model
sourceComponent: someComponent
}
The code above will not work. And I cannot find a way to make the
"model" context property available to the loader source component. For
reference:
http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-loader.html#using-a-loader-within-a-view-delegate
See especially the last code snippet there. Notice how the variable name
had to be changed from "index" to "modelIndex", in order to workaround
the issue I described above.
However, renaming properties is not always desirable.
Are there some tricks I'm not aware of? If not, what about introducing a
reserved word (maybe "qmlContext"), and let it refer to the current context?
So, one could write qmlContext.variableName to avoid ambiguity with
properties names "variableName", and my example above would change like
this:
Loader {
property variant model: qmlContext.model
sourceComponent: someComponent
}
Thoughts?
Ciao,
Alberto
--
http://blog.mardy.it <- geek in un lingua international!
More information about the Development
mailing list