From b68ad5ef7fd8df0ef4aea03f33dfe05fd8272469 Mon Sep 17 00:00:00 2001 From: Fabian Kosmale Date: Mon, 13 Mar 2023 09:36:09 +0100 Subject: [PATCH] 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. Pick-to: 6.5 dev Change-Id: I825265ad16e274c08b2c4a3a4814475b6c6c6187 Reviewed-by: Volker Hilsheimer Reviewed-by: Marc Mutz --- src/corelib/kernel/qmetatype.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 139c4ec7762..bf75e176b8e 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -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()); + } +#endif + QReadWriteLock lock; QList registry; QHash aliases;