c++qt5qmetatype

What is the difference between Q_ENUM and Q_ENUMS


I just found multiple examples showing the usage of Q_ENUM and Q_ENUMS and looking into the definition of Q_ENUM showed me that it includes Q_ENUMS and other definitions.

I am not sure which one to write when using the enum in Q_PROPERTY, Qml/QtQuick, in signals/slots, QVariants and qDebug() output.

It seems like the Q_ENUM is the better one as it is defined using Q_ENUMS, but I'm just guessing here.

What exactly are the differences, why are there two at all and which one should be prefered?


Solution

  • The What's New in Qt 5.5 says:

    Added Q_ENUM to replace Q_ENUMS, which allows to get a QMetaEnum at compile time using QMetaEnum::fromType. Such enums are now automatically registered as metatypes, and can be converted to strings within QVariant, or printed as string by qDebug().