QMetaType: Ensure that qfloat16 gets correct id

Code initially compiled against Qt <= 6.2 does not have a qfloat16
metatype that unconditionally gets registeret from QtBase.

Therefore, any preexisting metatype instance for qfloat16 will hit the
custom type registry code path. As builtin metatypes are not part of the
custom registry, we will create a new type-id, and the type will thus
not compare equal to new code using the builtin type-id.

Avoid this issue by inserting an alias to the type in
QMetaTypeCustomRegistry's constructor.

Change-Id: I825265ad16e274c08b2c4a3a4814475b6c6c6187
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit b68ad5ef7fd8df0ef4aea03f33dfe05fd8272469)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Fabian Kosmale 2023-03-13 09:36:09 +01:00 committed by Qt Cherry-pick Bot
parent e7b8b7bfbe
commit 6d054270fc

View File

@ -84,6 +84,20 @@ struct QMetaTypeDeleter
struct QMetaTypeCustomRegistry
{
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) && !defined(QT_BOOTSTRAPPED)
QMetaTypeCustomRegistry()
{
/* qfloat16 was neither a builtin, nor unconditionally registered
in QtCore in Qt <= 6.2.
Inserting it as an alias ensures that a QMetaType::id call
will get the correct built-in type-id (the interface pointers
might still not match, but we already deal with that case.
*/
aliases.insert("qfloat16", QtPrivate::qMetaTypeInterfaceForType<qfloat16>());
}
#endif
QReadWriteLock lock;
QList<const QtPrivate::QMetaTypeInterface *> registry;
QHash<QByteArray, const QtPrivate::QMetaTypeInterface *> aliases;