summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2021-03-23 17:04:37 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2021-03-25 17:33:07 +0100
commitcb43aaca112c864a201b87037692cb8ae2e93b6d (patch)
tree4118aa054133f6c72a7185ac0adbfd8eaf2f190b /tests
parent9145650302d3cfe7df0fbc2a11f5d8f5f867897d (diff)
Introduce QMetaObject::metaType
This function returns the metatype corresponding to the metaobject, or an invalid metatype for namespaces. This works as follows: First we increment the metaobject revision for new metaobjects. Metaobjects with older revisions are handled by doing a lookup by name. That fallback is also used for dynamic metaobjects (from QtDBUS and those created by QMetaObjectBuilder). For new metaobjects, we store the metatype in its metatype array, behind the property metatypes. This avoids any changes to the property and method metatype extraction logic: For properties, the metatype access does not change, as the new metatype is after their metatypes. For method metatypes, we already have an indirection layer (using offsets), so by adjusting those offsets by one, the same logic keeps working. To distinguish between namespaces and dynamic metaobjects, namespaces store the metatypeinterface pointer for void in the metatype array, whereas dynamic metaobjects store a nullptr. One nice additional benefit is that this simplifies the generator logic in moc, as the metatype array is now never empty. Task-number: QTBUG-92077 Change-Id: Id3f920f28553f12032a71a1a87dad29e5374dbe7 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
index 86501b74ea..968ccee043 100644
--- a/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
+++ b/tests/auto/corelib/kernel/qmetaobject/tst_qmetaobject.cpp
@@ -315,6 +315,8 @@ private slots:
void propertyConstant();
void propertyFinal();
+ void metaType();
+
void stdSet();
void classInfo();
@@ -1612,6 +1614,15 @@ void tst_QMetaObject::propertyFinal()
QVERIFY(!prop.isFinal());
}
+void tst_QMetaObject::metaType()
+{
+ QCOMPARE(QObject::staticMetaObject.metaType(), QMetaType::fromType<QObject>());
+ QCOMPARE(MyGadget::staticMetaObject.metaType(), QMetaType::fromType<MyGadget>());
+ QCOMPARE(QAbstractProxyModel::staticMetaObject.metaType(), QMetaType::fromType<QAbstractProxyModel>());
+ auto qtNameSpaceMetaType = Qt::staticMetaObject.metaType();
+ QVERIFY2(!qtNameSpaceMetaType.isValid(), qtNameSpaceMetaType.name());
+}
+
class ClassInfoTestObjectA : public QObject
{
Q_OBJECT