Hi,

I'm looking into using enum classes (c++11) and exposing them to QML as a
part of planning a new project. It will use Qt 5.5 so I'm using Qt 5.5
alpha for now.

I'd like to use enum classes for the enums, but I'm not sure if it is
possible to use these in QML. Let's say I have two enums in a class,

TestClass
{
   Q_GADGET

public:
   enum class Something { Undef, On, Off };
   Q_ENUM(Something)
   enum class Other { Undef = 5, On = 6, Off = 10, Maybe = 255 };
   Q_ENUM(Other)
};

In my main.cpp I register this like so

qmlRegisterUncreatableType<TestClass>("Test",1,0,"Test","Error...");

There does not seem to be any way in QML to differ between the two enum
classes. Looks like the values of the second defined class are used (so in
QML, Test.Undef will have the value of 5).

I tried registering the enum classes, but that doesn't work
(qmlRegisterUncreatableType<TestClass::Something> ... )

Do any of you know a way around this? The obvious fallback is to use unique
enum keys like when not using enum classes, (SomethingUndef, SomethingOn,
etc..), but I'd like not to, if it can be avoided.

Cheers,
Ola
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to