Q_OBJECT macro generation
-
I have read that when Q_OBJECT macro is placed inside a class, some meta-object code is generated. Is this code generated as body of the Q_OBJECT macro? What's more does the generated code provide a signal/slot mechansim for a class in general or only for user-defined signals and slots?
-
@michalt38 said in Q_OBJECT macro generation:
Is this code generated as body of the Q_OBJECT macro?
No, moc generates additional source code files, see https://doc.qt.io/qt-5/why-moc.html
-
@michalt38
It expands to this
Basically it inserts a static MetaObject.#define Q_OBJECT \ public: \ QT_WARNING_PUSH \ Q_OBJECT_NO_OVERRIDE_WARNING \ static const QMetaObject staticMetaObject; \ virtual const QMetaObject *metaObject() const; \ virtual void *qt_metacast(const char *); \ virtual int qt_metacall(QMetaObject::Call, int, void **); \ QT_TR_FUNCTIONS \ private: \ Q_OBJECT_NO_ATTRIBUTES_WARNING \ Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \ QT_WARNING_POP \ struct QPrivateSignal {}; \ QT_ANNOTATE_CLASS(qt_qobject, "")
-
@michalt38
For signal and slot in general.However, its now a slight grey area with the new pointer to method based connect syntax as
i think you can skip the Q_OBJECT now if you dont have any custom signals.
And you dont have to flag a slot with the slot macro anymore to use it as any member method can now be used as a slot. with the "new" connect syntax.