View Full Version : Expose C++ enum to QML

6th June 2011, 05:18
I searched but found nothing about this problem. Thanks for any help.

How to expose C++ enum in a namespace to QML ?

I've enum Presence in namespace A::B.
enum Presence used in class C, with declration: Q_ENUMS(A::B::Presence).

But I don't know how to export and use enum A::B::Presence in QML.

6th June 2011, 09:22
i didn't use namespace but i don't think it's managed into qml (i think it is to use in the export of your class)
to use the enum just type C.presenceValue in the qml

29th June 2011, 14:02
Did you find a solution about that problem ?

3rd August 2011, 06:43
the Q_ENUMS declaration should exist within a class which inherits QObject, and contains the Q_OBJECT macro.

then, the simplest method would be to expose an instance of this class via QDeclarativeContext::setContextProperty().

once referenced as a Q_ENUM, an enumeration instance of that type can be referenced as a standard property by Qt: http://www.maemonokian900.com/maemo-news/using-c-enums-in-qml/