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

Enums from separate header are not registered to qml

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.0
    • Build tools: moc
    • None
    • All

    Description

      We have a problem when we can't expose enums to qml.

      Our current setup is the following:

      We have multiple headers that contain c++ enums, unfortunately we cannot merge them into one:

      // HeaderE1.hh
      namespace bda {
      enum E1 {
          E1_1,
          E1_2,
      };
      }
      // HeaderE2.hh
      namespace bda {
      enum E2 {
          E2_1,
          E2_2,
      };
      }

      Then we want to expose these enums to QML, since Q_NAMESPACE can only be used once, we are doing that in a single header like so:

      // HeaderQml.hh
      #include "HeaderE1.hh"
      #include "HeaderE2.hh"
      namespace bda {
      Q_NAMESPACE
      Q_ENUM_NS(E1)
      Q_ENUM_NS(E2)
      }
      class BDAEnumsQml : public QObject {
          Q_OBJECT
          QML_ELEMENT
          QML_EXTENDED_NAMESPACE(bda)
          QML_UNCREATABLE("This is a wrapper for exposing enums to QML, do not create instances of this class.")
      };
      

      But with this setup, the values are not correctly exported to qml and we don't see the enums in .qmltypes file. This works if we move enums to HeaderQml.hh, but unfortunately we cannot do that.

      Do you have any suggestions how to fix this?

      Attachments

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

        Activity

          People

            fabiankosmale Fabian Kosmale
            friendnick Mykola Vankovych
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes