diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp index 73a951c39b7..67911f2836d 100644 --- a/src/corelib/kernel/qvariant.cpp +++ b/src/corelib/kernel/qvariant.cpp @@ -3161,8 +3161,15 @@ bool QVariant::cmp(const QVariant &v) const else return toLongLong() == v.toLongLong(); } - if (!v2.canConvert(v1.d.type) || !v2.convert(v1.d.type)) - return false; + if (v2.canConvert(v1.d.type)) { + if (!v2.convert(v1.d.type)) + return false; + } else { + // try the opposite conversion, it might work + qSwap(v1, v2); + if (!v2.convert(v1.d.type)) + return false; + } } if (v1.d.type >= QMetaType::User) { int result; diff --git a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp index 10c7e425f0b..eae6311854e 100644 --- a/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/auto/corelib/kernel/qvariant/tst_qvariant.cpp @@ -43,7 +43,7 @@ #include #include #include - +#include #include #include @@ -1436,6 +1436,13 @@ void tst_QVariant::operator_eq_eq_data() QTest::newRow("invalidConversionR") << QVariant(0) << QVariant(QString("bubu")) << false; // ### many other combinations missing + { + // QUuid can convert to QString, but not the opposite + QUuid uuid(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + QTest::newRow("uuidstring") << QVariant(uuid) << QVariant(uuid.toString()) << true; + QTest::newRow("stringuuid") << QVariant(uuid.toString()) << QVariant(uuid) << true; + } + { QMap map1; map1.insert( "X", 1 );