Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use common enum in both C++ and qml.??
Forum Updated to NodeBB v4.3 + New Features

How to use common enum in both C++ and qml.??

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aekam
    wrote on last edited by
    #1

    I have an enum in enumFile.h.
    I want to use it in signal-slot functions in a class, so i used qRegisterMetaType<enum>("enum") in constructor.
    I also want to use it in qml, for which i have to have a copy of that enum in class which i bind with qml and use Q_ENUM(enum) macro to make it visible in qml.

    so is there any method by which i can have a common enum in enum.h, and use it in signal-slot and also in qml files.?

    If you take care of inches, you won't have to worry about miles... :)

    1 Reply Last reply
    0
    • B Offline
      B Offline
      billouparis
      wrote on last edited by
      #2

      Hey, did you find a solution?
      Thank you,
      Bill

      1 Reply Last reply
      0
      • C Offline
        C Offline
        CreMindES
        wrote on last edited by
        #3

        I would also be interested in this solution.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          billouparis
          wrote on last edited by
          #4

          hey CreMindES. Any expertise in the Q_DECLARE_METATYPE maybe to solve this issue, in conjonction with the qmlRegisterUncreatableType?

          I even tried to define a macro in an external file to declare my enum, and then simply put my macro like this:
          @MyClass: public QObject
          {
          Q_OBJECT
          Q_ENUMS(MyEnum)

          public:
          MACRO
          }

          and MACRO being defined in an external file.h like:
          #define MACRO
          enum MyEnum { A, B, C};
          @

          But even this does not work, I always get an undefined value in the QML when trying to use A, B or C

          Any more luck?
          Bill

          1 Reply Last reply
          0
          • B Offline
            B Offline
            billouparis
            wrote on last edited by
            #5

            So OK the moc does not preprocess my macro apparently, and therefore the Q_ENUMS does not know about MyEnum while the moc is preprocessing it. But what is the solution then?

            Bill

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved