[Development] Enumerations in QML

Charley Bay charleyb123 at gmail.com
Wed Dec 12 13:51:36 CET 2012


Unto all so did sayeth Alan:

> > What should enumeration declarations in QML look like?
>

Did respondeth Erik:

> And, also important: how much slower is it allowed to be than the current
> implementation?
>
> I remembered that there was talk about enums in QML before, so I dug
> around a bit, and behold:
>
> The problem with enums is that we couldn't make them fast. They will
> always be a lot slower than normal string literals. That is mostly because
> we could not avoid the name lookup.


>    Text {
>            alignment: Alignment.Vertical | Alignment.something
>     }
>
> there is no way for you to remove the name lookups for "Alignment",
> "Vertical", and "something". Also, there is no way for you to distinguish
> "Types" (e.g. Item, Rectangle, and co...) from "Enums" (in our case
> "Alignment"). That means, you cannot build the correct list of dependencies
> when loading a QML Component.
>

Ouch.  That is quite unexpected.

We seem to have multiple intentions regarding adding "Enums" to QML:

 (1) Those with a "native" (C/C++) background may have thought "Enum" to be
faster than "String" (e.g., "performance-goal")

 (2) Some may prefer the "cleaner-look" by using an unquoted "Enum" over a
quoted string literal

 (3) Some may expect a "compile-time" check for (valid) enumerated-values,
as compared with a "run-time" check with string-lookups (? this may not be
a real consideration depending on how the QML parsing engine works)

 (4) Lack of "Enums" in QML is (another) example of how QML might be
considered a "second-class-citizen" (mentioned by Chris, another example
being composite types in QML are not backed by a QQmlType and thus are not
available in JavaScript as are types defined in C++)

IMHO, the "performance" is the biggest issue, as we have currently
work-arounds to enable enumerations in QML.

Some of the "post-V8-engine" discussion may address the performance issue,
at which point all of the above considerations could be achieved.  (Lars
may comment on this?)

So:  I want "Enums" in QML, but only if they are as-fast-or-faster than
string lookups.  I'm quite happy to defer this feature until that can be
achieved.

--charley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20121212/ce55b5fd/attachment.html>


More information about the Development mailing list