PDA

View Full Version : Expose C++ enum to QML



OnlyK
6th June 2011, 06: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.

Le_B
6th June 2011, 10: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

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

vallidor
3rd August 2011, 07: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/