[Development] Perceptions/Understandings of the QML language [was: Question about Qt's future]
Simon Hausmann
simon.hausmann at digia.com
Wed Apr 30 11:36:41 CEST 2014
On Wednesday 30. April 2014 11.19.45 André Somers wrote:
> Simon Hausmann schreef op 30-4-2014 10:51:
> >> - objects can be put in the context in c++
> >
> > Ah, setContextProperty? Yeah, we could warn against that.
>
> Could you, or somebody else, elaborate a bit on why this is bad
> practice? To my (admittedly naive) eyes, it seems like a good and simple
> way, available right now, to separate the declarative QML from
> imperative code.
One disadvantage is performance.
There are two primary ways of exposing objects into the scope of a QML
context, from where they are accessible:
1) Dynamically, for example through the return value of a function or through
context properties. The time as to when those objects are available is
determined at run-time, and their type is entirely dynamic.
2) "Statically" through the QML type system. Either as objects that can be
instantiated or through singletons (the C++ kind, not the QJSValue type). They
are "entered" into the context through the imports, their existence is known
at QML type compile time as well as their concrete type.
Naturally the second option allows for a much broader range of optimizations
at type-compile time. For example in order to resolve
"MySingleton.someProperty", we first need to resolve "MySingleton" (as string)
to an index in the vector of singletons and then resolve "someProperty" to a
meta-property index. Both of these can be done at type-compile time, avoiding
repeated string operations every time "MySingleton.someProperty" needs to be
evaluated.
Simon
More information about the Development
mailing list