QMetaClassInfo是QMetaObject中用于存放类信息的数据结构
QMetaClassInfo定义:
class Q_CORE_EXPORT QMetaClassInfo
{
public:
Q_DECL_CONSTEXPR inline QMetaClassInfo() : mobj(nullptr), handle(0) {}
const char *name() const;
const char *value() const;
inline const QMetaObject *enclosingMetaObject() const { return mobj; }
private:
const QMetaObject *mobj;
uint handle;
friend struct QMetaObject;
};
产生:
必须在类声明中带有Q_CLASSINFO声明,如
class XTest : public QObject
{
Q_OBJECT
Q_CLASSINFO("author", "Sabrina Schweinsteiger")
public:
XTest(QObject* p = nullptr);
~XTest();
public slots:
void slot1(double * p1);
Q_INVOKABLE void slot2(int * p2);
Q_REVISION(1) void slot3(char * p3);
signals:
void sig1(void * p4);
};
成员变量:
const QMetaObject *mobj指向所属类的QMetaObject
uint handle指向类名字符串的首地址
如moc文件解析一篇中qt_meta_stringdata_XTest是XTest的QMetaObject::d.stringdata属性,XTest中QMetaClassInfo::mobj指向XTest::QMetaObject,QMetaClassInfo::handle值为"XTest"字符串的首地址位置
qt_meta_stringdata_XTest定义如下:
static const qt_meta_stringdata_XTest_t qt_meta_stringdata_XTest = {
{
QT_MOC_LITERAL(0, 0, 5), // "XTest"
QT_MOC_LITERAL(1, 6, 6), // "author"
QT_MOC_LITERAL(2, 13, 22), // "Sabrina Schweinsteiger"
QT_MOC_LITERAL(3, 36, 4), // "sig1"
QT_MOC_LITERAL(4, 41, 0), // ""
QT_MOC_LITERAL(5, 42, 2), // "p4"
QT_MOC_LITERAL(6, 45, 5), // "slot1"
QT_MOC_LITERAL(7, 51, 7), // "double*"
QT_MOC_LITERAL(8, 59, 2), // "p1"
QT_MOC_LITERAL(9, 62, 5), // "slot2"
QT_MOC_LITERAL(10, 68, 4), // "int*"
QT_MOC_LITERAL(11, 73, 2), // "p2"
QT_MOC_LITERAL(12, 76, 5), // "slot3"
QT_MOC_LITERAL(13, 82, 5), // "char*"
QT_MOC_LITERAL(14, 88, 2) // "p3"
},
"XTest\0author\0Sabrina Schweinsteiger\0"
"sig1\0\0p4\0slot1\0double*\0p1\0slot2\0int*\0"
"p2\0slot3\0char*\0p3"
};
主要提供以下函数:
QMetaClassInfo::name
返回classinfo的名称qt_meta_stringdata_XTest中的"author"字段
QMetaClassInfo::value
返回classinfo的值qt_meta_stringdata_XTest中的"Sabrina Schweinsteiger"字段
enclosingMetaObject
返回QMetaObject * QMetaClassInfo::mobj