From 98e21f0979143a1e278572390012f021dfed1b6a Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 25 Aug 2022 15:59:39 -0300 Subject: QVariant: fix conversions of string keys to Q_ENUM that are QFlags<> Since Qt 6.0, QMetaType stores the name obtained from the C++ compiler, which means we know a type like Qt::Alignment by its proper, full name of QFlags. However, the meta object records only the bare name of the enumeration, not the full flags. Pick-to: 6.2 6.3 6.4 Fixes: QTBUG-105932 Fixes: QTBUG-96185 Change-Id: Ic6547f8247454b47baa8fffd170eab977e306377 Reviewed-by: Fabian Kosmale --- src/corelib/kernel/qmetatype.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/corelib/kernel/qmetatype.cpp') diff --git a/src/corelib/kernel/qmetatype.cpp b/src/corelib/kernel/qmetatype.cpp index e4ef2f7665..927c258647 100644 --- a/src/corelib/kernel/qmetatype.cpp +++ b/src/corelib/kernel/qmetatype.cpp @@ -1871,10 +1871,16 @@ static QMetaEnum metaEnumFromType(QMetaType t) { if (t.flags() & QMetaType::IsEnumeration) { if (const QMetaObject *metaObject = t.metaObject()) { - const QByteArray enumName = t.name(); - const char *lastColon = std::strrchr(enumName, ':'); - return metaObject->enumerator(metaObject->indexOfEnumerator( - lastColon ? lastColon + 1 : enumName.constData())); + QByteArrayView qflagsNamePrefix = "QFlags<"; + QByteArray enumName = t.name(); + if (enumName.endsWith('>') && enumName.startsWith(qflagsNamePrefix)) { + // extract the template argument + enumName.chop(1); + enumName = enumName.sliced(qflagsNamePrefix.size()); + } + if (qsizetype lastColon = enumName.lastIndexOf(':'); lastColon != -1) + enumName = enumName.sliced(lastColon + 1); + return metaObject->enumerator(metaObject->indexOfEnumerator(enumName)); } } return QMetaEnum(); @@ -2524,7 +2530,7 @@ bool QMetaType::canConvert(QMetaType fromType, QMetaType toType) return true; } const ConverterFunction * const f = - customTypesConversionRegistry()->function(qMakePair(fromTypeId, toTypeId)); + customTypesConversionRegistry()->function(std::make_pair(fromTypeId, toTypeId)); if (f) return true; -- cgit v1.2.3