From 36640aa0afb722479ba47d6fbd9401c433dead41 Mon Sep 17 00:00:00 2001 From: Alex Blasche Date: Wed, 3 Jun 2015 15:28:01 +0200 Subject: Don't enforce all QMetaType::TypeFlag difference across Qt versions QMetaType::IsGadget was introduced in Qt 5.5 and set when Q_GADGET is used. If an existing Qt 5.4 class was converted to a gadget in Qt 5.5+, the two types would have differing QMetaType::TypeFlags. Such a conversion happened for QGeoCoordinate, QGeoShape, QGeoRectangle and QGeoCircle. There might be other classes too. In principle, the same problem exists for every future addition to QMetaType::TypeFlag too. This patch ensures that new flags are kept in the metatype database and the related qFatal call is not triggered for any flag >= TypeFlag::WasDeclaredAsMetaType. Change-Id: Ibb15daeb28d9a11b7f31658f4219cbca2499213f Task-number: QTBUG-46454 Reviewed-by: Alex Blasche Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/corelib/kernel/qmetatype.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index 3b70ef92ed..0f9cf41b77 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1046,6 +1046,16 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, if (idx >= User) { previousSize = ct->at(idx - User).size; previousFlags = ct->at(idx - User).flags; + + // Set new/additional flags in case of old library/app. + // Ensures that older code works in conjunction with new Qt releases + // requiring the new flags. + if (flags != previousFlags) { + QCustomTypeInfo &inf = ct->data()[idx - User]; + inf.flags |= flags; + if (metaObject) + inf.metaObject = metaObject; + } } } @@ -1061,11 +1071,11 @@ int QMetaType::registerNormalizedType(const NS(QByteArray) &normalizedTypeName, normalizedTypeName.constData(), idx, previousSize, size); } + // Do not compare types higher than 0x100: // Ignore WasDeclaredAsMetaType inconsitency, to many users were hitting the problem - previousFlags |= WasDeclaredAsMetaType; - flags |= WasDeclaredAsMetaType; - - if (previousFlags != flags) { + // Ignore IsGadget as it was added in Qt 5.5 + // Ignore all the future flags as well + if ((previousFlags ^ flags) & 0xff) { const int maskForTypeInfo = NeedsConstruction | NeedsDestruction | MovableType; const char *msg = "QMetaType::registerType: Binary compatibility break. " "\nType flags for type '%s' [%i] don't match. Previously " -- cgit v1.2.3