summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-02-03 17:31:11 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2023-02-08 23:20:42 +0100
commit66a1a71f1f92156548da487739129fb0f494c895 (patch)
treed03b90060e7361e58613a657b2dad8b726cfc213 /tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
parente30ed4d4318f95ca704873aba745ca222d03edcb (diff)
Fix QVariant(QString) <-> enum conversion
A QVariant(QString) was not convertible to an enum not registered with Q_ENUM() which worked fine in Qt5. The same problem exists for QVariant(enum) to QString. Fix it by not bailing out when no metatype for the enum was found and try to convert it to a qlonglong instead (which is then correctly converted to the enum type). Fixes: QTBUG-109744 Pick-to: 6.5 6.4 Change-Id: Ie7bb016a860455b69508f0f46b36474c9c294f3a Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp')
-rw-r--r--tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
index fbd17f94b2..87b9e20770 100644
--- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -4982,6 +4982,13 @@ template <auto value> static void testVariantEnum()
QVERIFY(var2.convert(QMetaType::fromType<int>()));
QCOMPARE(var2.value<int>(), static_cast<int>(value));
+ QVariant strVar = QString::number(qToUnderlying(value));
+ QVariant baVar = QByteArray::number(qToUnderlying(value));
+ QCOMPARE(strVar.value<Enum>(), value);
+ QCOMPARE(baVar.value<Enum>(), value);
+ QCOMPARE(var.value<QString>(), strVar);
+ QCOMPARE(var.value<QByteArray>(), baVar);
+
// unary + to silence gcc warning
if (losslessConvertToInt) {
int intValue = static_cast<int>(value);