Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-137534

Moc compiler fails to generate enum metainformation with X Macros

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.9.1
    • Build tools: moc
    • None
    • Linux/X11

    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) 
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            fabiankosmale Fabian Kosmale
            r.vitanov Rosen Vitanov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes