summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-07-19 11:45:40 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-07-26 14:33:21 -0700
commitb1d9331c156b7ff5c724600eee21ac50f4565868 (patch)
tree28d5c40c9c3ff4b04579621e0421eed3617089f6
parent51905f8e7638e997653c3fc10b97a66fe305edf9 (diff)
QMetaType: fix isRegistered()
It's not registered until an ID is assigned. Pick-to: 6.4 Change-Id: I3859764fed084846bcb0fffd17034f5b369c5b4d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/corelib/kernel/qmetatype.cpp11
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp9
-rw-r--r--tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h1
3 files changed, 18 insertions, 3 deletions
diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp
index 7f44018717..4aed2edebb 100644
--- a/src/corelib/kernel/qmetatype.cpp
+++ b/src/corelib/kernel/qmetatype.cpp
@@ -468,6 +468,8 @@ const char *QtMetaTypePrivate::typedefNameForType(const QtPrivate::QMetaTypeInte
Returns \c true if this QMetaType object contains valid
information about a type, false otherwise.
+
+ \sa isRegistered()
*/
bool QMetaType::isValid() const
{
@@ -478,12 +480,15 @@ bool QMetaType::isValid() const
\fn bool QMetaType::isRegistered() const
\since 5.0
- Returns \c true if this QMetaType object contains valid
- information about a type, false otherwise.
+ Returns \c true if this QMetaType object has been registered with the Qt
+ global metatype registry. Registration allows the type to be found by its
+ name (using QMetaType::fromName()) or by its ID (using the constructor).
+
+ \sa qRegisterMetaType(), isValid()
*/
bool QMetaType::isRegistered() const
{
- return d_ptr;
+ return d_ptr && d_ptr->typeId.loadRelaxed();
}
/*!
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
index facd9992b9..9a3ab830cb 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -861,6 +861,7 @@ void tst_QMetaType::sizeOf()
{
QFETCH(int, type);
QFETCH(size_t, size);
+ ignoreInvalidMetaTypeWarning(type);
QCOMPARE(size_t(QMetaType::sizeOf(type)), size);
}
@@ -873,6 +874,7 @@ void tst_QMetaType::sizeOfStaticLess()
{
QFETCH(int, type);
QFETCH(size_t, size);
+ ignoreInvalidMetaTypeWarning(type);
QCOMPARE(size_t(QMetaType(type).sizeOf()), size);
}
@@ -909,6 +911,7 @@ void tst_QMetaType::alignOf()
{
QFETCH(int, type);
QFETCH(size_t, size);
+ ignoreInvalidMetaTypeWarning(type);
QCOMPARE(size_t(QMetaType(type).alignOf()), size);
}
@@ -1534,6 +1537,12 @@ void tst_QMetaType::isRegisteredStaticLess()
QCOMPARE(QMetaType(typeId).isRegistered(), registered);
}
+struct NotARegisteredType {};
+void tst_QMetaType::isNotRegistered()
+{
+ QVERIFY(!QMetaType::fromType<NotARegisteredType>().isRegistered());
+}
+
typedef QHash<int, uint> IntUIntHash;
Q_DECLARE_METATYPE(IntUIntHash)
typedef QMap<int, uint> IntUIntMap;
diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h
index a30963a919..37d9f958e9 100644
--- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h
+++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.h
@@ -84,6 +84,7 @@ private slots:
void isRegistered();
void isRegisteredStaticLess_data();
void isRegisteredStaticLess();
+ void isNotRegistered();
void isEnum();
void automaticTemplateRegistration_1();
void automaticTemplateRegistration_2(); // defined in tst_qmetatype3.cpp