Solved Q_PROPERTY and enum
-
Hello everyone, I have a problem with enum and Q_PROPERTY.
I created an enum in a class:class ClassA { Q_OBJECT public: enum Enum_Test { eTestA, eTestB } ... }
In another class I call this enum in the properties:
#include "ClassA.h" class ClassB { Q_OBJECT Q_ENUMS(ClassA::Enum_Test) Q_PROPERTY(ClassA::Enum_Test enumTest READ GetEnumTest WRITE SetEnumTest ) ... }
Despite using the Q_ENUMS gives me the following error:
QMetaProperty::read: Unable to handle unregistered datatype 'ClassA::Enum_Test' for property 'ClassB::enumtest'I can not understand where I'm wrong.
Unfortunately I am obliged to have the Enum in different class from the properties.
Thanks -
- Q_ENUMS is deprecated, use Q_ENUM, see https://woboq.com/blog/q_enum.html
- depending on the usage you might also have to register the enum metatype: http://doc.qt.io/qt-5/qmetatype.html#qRegisterMetaType-1
-
Thanks, now work fine.
I use Q_ENUM and I moved it in ClassAclass ClassA { Q_OBJECT public: enum Enum_Test { eTestA, eTestB } Q_ENUM(Enum_Test) ... } #include "ClassA.h" class ClassB { Q_OBJECT Q_PROPERTY(ClassA::Enum_Test enumTest READ GetEnumTest WRITE SetEnumTest ) ... }
thanks