The Q_GADGET macro is a lighter version of the Q_OBJECT macro for classes that do not inherit from QObject but still want to use some of the reflection capabilities offered by QMetaObject. Just like the Q_OBJECT macro, it must appear in the private section of a class definition.
The Q_GADGET
macro is a lighter version of the Q_OBJECT
macro for classes that do not inherit from QObject
but still want to use some of the reflection capabilities offered by QMetaObject
. Just like the Q_OBJECT
macro, it must appear in the private
section of a class definition.
Q_GADGET
makes a class member, staticMetaObject
, available. staticMetaObject
is of type QMetaObject
and provides access to the enums declared with Q_ENUMS
.
Since Qt 5.5 Q_GADGET
s can have Q_ENUM
, Q_PROPERTY
and Q_INVOKABLE
but, differently from Q_OBJECT
, they cannot declare signals or slots.
Thanks to these new features, Q_GADGET
macro can be used to register so called custom QML value type as explained in the documentation.