[Development] [QML] Assigning ints to enumeration properties
416365416c at gmail.com
Tue Mar 5 22:34:14 CET 2013
I'd like to make a slight change to enum property behavior in QML.
Currently you get a compile error if you assign an int to an enum
property, similar to the warning you'll get in C++ if you do the same.
However in C++ you can easily work around this by casting it to the
enum, or just ignoring the warning. Neither option is available in
Note that since this relaxes the constraints of the language,
previously running QML will continue to run as before.
I'll enumerate the pros and cons:
-Matches expectations from C++ users a little better
-Matches expectations from script users a little better
-Code is usually less readable when you use ints.
-Less typesafe (although the actual type of enum isn't checked, merely
that it is an enum, so it's not that big a loss).
And a further quirk, you can already get this behavior if you make
your properties int properties instead of enums currently (because
enums can be assigned to int properties). However this is ugly for
classes which are also exposed as C++ APIs, as they'd much prefer to
use enums for a good C++ API.
Since it's a bit of a borderline issue, with minimal gains or losses,
I'd like some further opinions on the issue. Does anyone feel strongly
for or against this change?
More information about the Development