[Development] [QML]: Register global enums/flags to QML ?
Olivier Goffart
olivier at woboq.com
Thu Jul 28 09:22:37 CEST 2016
On Dienstag, 26. Juli 2016 18:18:48 CEST BogDan Vatra wrote:
> 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.
Yes, i think a Q_NAMESPACE would be a nice addition in order to allow Q_ENUM
at namespace scope. We have some example for example in the QSsl namespace
that has enumerations.
One issue is that moc need to have a complete view of the namespace as it
generates the QMetaObject for it, so it should not be possible to have Q_ENUM
in a other header than the one which have the Q_NAMESPACE keyword.
--
Olivier
Woboq - Qt services and support - https://woboq.com - https://code.woboq.org
More information about the Development
mailing list