[Development] [QML]: Register global enums/flags to QML ?

BogDan Vatra bogdan at kdab.com
Tue Jul 26 17:18:48 CEST 2016


Hello,

I'd like to be able to register some "global" enums/flags to QML. I checked a 
little bit how Qt does with all the enums from Qt namespace (qnamespace.h) and 
I end-up in qqmlbuiltinfunctions which does all the "magic" which can't be 
used by normal developers/libs.

Because I think having "global" enums is a very nice feature, I'd like to know 
if other people and QML maintainers agree with me :). 
If yes, then want to propose the followings:
 - add one more Q_OBJECT/Q_GADGET like macro for namespaces (Q_NAMESPACE?), 
which declares the mandatory "extern const QMetaObject staticMetaObject" ( or 
just "extern const QMetaEnum  staticMetaEnum" ? because in principle we'll 
only be able to declare enums/flags ?) into that namespace. Most probably moc 
will need some love to properly handle the new Q_magic_macro. If is too much 
trouble we can use the qnamespace.h hack.

 - add a helper macro/function to register the namespace enums/flags (i.e. 
qmlRegisterNamespace or even better qmlRegisterEnums(const QMetaEnum 
&staticMetaEnum, ....). 

I think it depends on QML c++11 scoped enums task, because most probably the 
enums enumerators names will clash.

Cheers,
BogDan.




More information about the Development mailing list