Search code examples
c++qtenums

Qt enum in signal requires qRegisterMetaType


I have an enum and a property in my QObject-based class like:

Q_ENUMS(StateEnum)
Q_PROPERTY(StateEnum state READ state NOTIFY stateChanged)

When I try to emit stateChanged(state), I receive an error:

QObject::connect: Cannot queue arguments of type 'StateEnum'
(Make sure 'StateEnum' is registered using qRegisterMetaType().)

Why do I need to invoke qRegisterMetaType? I thought that is what Q_ENUMS does.


Solution

  • You are looking for the Q_ENUM() macro. This replaces the now-deprecated Q_ENUMS and will automatically register the metatype.

    Your code should look like this:

    Q_ENUM(StateEnum) //note the missing 'S' here
    Q_PROPERTY(StateEnum state READ state NOTIFY stateChanged)