diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index af838ab090..dbc11c57ec 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -376,6 +376,13 @@ struct DefinedTypesFilter { information about a type, false otherwise. */ +/*! + \fn int QMetaType::id() const + \since 5.13 + + Returns id type hold by this QMetatype instance. +*/ + /*! \fn bool QMetaType::sizeOf() const \since 5.0 diff --git a/src/corelib/kernel/qmetatype.h b/src/corelib/kernel/qmetatype.h index ed7feee775..0bf430bb26 100644 --- a/src/corelib/kernel/qmetatype.h +++ b/src/corelib/kernel/qmetatype.h @@ -570,6 +570,7 @@ public: inline bool isValid() const; inline bool isRegistered() const; + inline int id() const; inline int sizeOf() const; inline TypeFlags flags() const; inline const QMetaObject *metaObject() const; @@ -2221,6 +2222,11 @@ inline bool QMetaType::isRegistered() const return isValid(); } +inline int QMetaType::id() const +{ + return m_typeId; +} + inline void *QMetaType::create(const void *copy) const { // ### TODO Qt6 remove the extension diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index 5d9b5ca95c..2d6961c209 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -73,6 +73,7 @@ private slots: void defined(); void threadSafety(); void namespaces(); + void id(); void qMetaTypeId(); void properties(); void normalizedTypes(); @@ -475,6 +476,12 @@ void tst_QMetaType::namespaces() QCOMPARE(QMetaType::typeName(qungTfuId), "TestSpace::QungTfu"); } +void tst_QMetaType::id() +{ + QCOMPARE(QMetaType(QMetaType::QString).id(), QMetaType::QString); + QCOMPARE(QMetaType(::qMetaTypeId()).id(), ::qMetaTypeId()); +} + void tst_QMetaType::qMetaTypeId() { QCOMPARE(::qMetaTypeId(), int(QMetaType::QString));