QMetaType: fix isRegistered()

It's not registered until an ID is assigned.

Change-Id: I3859764fed084846bcb0fffd17034f5b369c5b4d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit b1d9331c156b7ff5c724600eee21ac50f4565868)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Thiago Macieira 2022-07-19 11:45:40 -07:00 committed by Qt Cherry-pick Bot
parent fbdd3396c3
commit c4cea61cea
3 changed files with 18 additions and 3 deletions

View File

@ -465,6 +465,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
{
@ -475,12 +477,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();
}
/*!

View File

@ -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;

View File

@ -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