Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.1
-
None
Description
Using X-macros to define an enum inside a Q_OBJECT fails to generate the Q_ENUM information:
class MyEnumObject : public QObject { Q_OBJECT QML_ELEMENT QML_UNCREATABLE("Enum Class") public: MyEnumObject() = delete; enum Type { #define X(name, value, _) name = value, #include "my_enum_list.h" #undef X }; Q_ENUM(Type) };
Results in an empty meta_type definition in the qml modules meta_types folder.
The following is the enum definition in the meta_types json in the build folder:
"className": "WidgetTypeEnum", "enums": [ { "isClass": false, "isFlag": false, "name": "Type", "type": "uint32_t" } ],
If we define each value in the enum without an X Macro, the enums definition contains the enum names.
This makes the enum unusable in qml and all values are cast to 1.
This also works if there is another macro inside my_enum_list, e.g. X_MACRO_LIST and we use that macro in the wrapper definition. Seems to fail when having to unwrap the macros from the included file. So this works again:
enum Type { #define X(name, value, _) name = value, #include "my_enum_list.h" X_MY_ENUM_LIST #undef X }; Q_ENUM(Type)