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

Reusing enums does not work in Qml

    XMLWordPrintable

Details

    • All

    Description

      It is impossible to re-use the C++ enumerations for the Qml.

      F.e. I have somewhere the following C++ enum from the external source (library, package, etc):

      namespace origin {
      enum class State {
        Foo,
        Bar,
        Baz,
      };
      } // namespace origin
      

      And then I want to re-use this enum to use it from the Qml:

      namespace reused {
      Q_NAMESPACE
      using State = ::origin::State; // Here I'm try to re-use the origin::State enum for Qml
      Q_ENUMS(State) // or Q_ENUM_NS(State)
      } // namespace reused
      
      Q_DECLARE_METATYPE(reused::State)
      

      And then I do register the `reused` namespce metatype from the C++ code:

        qmlRegisterUncreatableMetaObject(reused::staticMetaObject, "my.test", 1, 0,
                                         "Reused", "Error: only enums");
      

      In Qml I expect that I will able to access to the `Reused.Foo` value from the Qml code:

      Window {
          width: 640
          height: 480
          visible: true
      
          property bool dummy: {
              console.info("** state: " + myobj.state)
              console.info("** foo: " + Reused.Foo)
              return false;
          }
      }
      

      But, it prints out the following:

      qml: ** state: 0
      qml: ** foo: undefined
      

      The MOC (or something else) does not parse the `using` or `typedef` keywords or etc...

      UPD: I have attached the qbsbug-99257.zip source example to reproduce an issue.

      Attachments

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

        Activity

          People

            qtqmlteam Qt Qml Team User
            kuzulis Denis Shienkov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes