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



  • 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?



  • Bump - anyone?



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.