Q_OBJECT
程序员文章站
2022-06-24 16:31:15
#define Q_OBJECT \public: \ Q_OBJECT_CHECK \ QT_WARNING_PUSH \ Q_OBJECT_NO_OVERRIDE_WARNING \ static const QMetaObject staticMetaObject; \ virtual const QMetaObject *metaObject() const; \ virtual void *qt_metacast(const char *); \....
#define Q_OBJECT \
public: \
Q_OBJECT_CHECK \
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, "")
- 公有QMetaObject静态对象staticMetaObject
- 私有qt_static_metacall静态函数
- virtual const QMetaObject *metaObject() const; \ 用于获取类静态拥有的元对象
- virtual void *qt_metacast(const char *); \ 通过元对象获取对象指针
- virtual int qt_metacall(QMetaObject::Call, int, void **); \ 用于信号槽机制
1:为该类型的所有对象共有,属于类变量。
2: 私有静态函数qt_static_metacall,类里使用
3.4.5 在MOC生成代码的时候会重写这些虚函数。
class QMetaObject {
struct { // private data
const QMetaObject *superdata;
const QByteArrayData *stringdata;
const uint *data;
typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
StaticMetacallFunction static_metacall;
const QMetaObject * const *relatedMetaObjects;
void *extradata; //reserved for future use
} d;
};
struct QArrayData
{
QtPrivate::RefCount ref;
int size;
uint alloc : 31;
uint capacityReserved : 1;
qptrdiff offset; // in bytes from beginning of header
}
<图片来源网络>
本文地址:https://blog.csdn.net/jadeshu/article/details/107060428