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. C++11 strongly typed enums in the signal/slot/ metaobject system?
Forum Updated to NodeBB v4.3 + New Features

C++11 strongly typed enums in the signal/slot/ metaobject system?

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.1k 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.
  • M Offline
    M Offline
    medvedm
    wrote on last edited by
    #1

    Is there any documentation on using the new c++11 strongly typed enums (enum class ) as types in the Qt metaojbect system?

    It is pretty clear how enums work in normal c++, with the Q_ENUMS and all that, but now that enums are levelled up, what happens? I want to declare an enum like:

    @
    enum class SystemState : quint8
    {
    NULL_STATE = 0,
    INITIALIZE_STATE = 1,
    OP_IDLE_STATE = 2,
    // .... etc
    };
    @

    And then use it in a class' signal:

    @
    signals:
    void stateChanged(SystemState newState);
    @

    Is there some documentation I missed in my googling?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      medvedm
      wrote on last edited by
      #2

      Bump - anyone?

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hi, Any type that may be used in the signal/slot mechanism should fit in a QVariant sized variable. To use other argument types the user should use the Q_DECLARE_METATYPE(type) to do so. I don't believe that the C++11 changes anything to that. So below the definition of your class add the
        @
        Q_DECLARE_METATYP(SystemState)
        @
        and you should be able to use the class in signal/slot use.

        Greetz, Jeroen

        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