summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2013-11-02 17:31:12 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-11-06 16:15:15 +0100
commit8ef5e700b8471b865328472b52a790686507bb45 (patch)
treed75535b0ac5f8b5c6f4872ca11dc2831ec1e4561
parent417cf3fc535ef18e7895cb863235cc33e36669f9 (diff)
QMetaType: Fix conversion between module types.
Change-Id: I7215b4599c3f0459139b32b6571f0a9e60182ee9 Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r--src/corelib/kernel/qvariant.cpp3
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp16
2 files changed, 18 insertions, 1 deletions
diff --git a/src/corelib/kernel/qvariant.cpp b/src/corelib/kernel/qvariant.cpp
index 5754af42ac..816c34a14d 100644
--- a/src/corelib/kernel/qvariant.cpp
+++ b/src/corelib/kernel/qvariant.cpp
@@ -2974,7 +2974,8 @@ bool QVariant::convert(int targetTypeId)
}
bool isOk = true;
- if (!handlerManager[d.type]->convert(&oldValue.d, targetTypeId, data(), &isOk))
+ int converterType = std::max(oldValue.userType(), targetTypeId);
+ if (!handlerManager[converterType]->convert(&oldValue.d, targetTypeId, data(), &isOk))
isOk = false;
d.is_null = !isOk;
return isOk;
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index 4b2cce63e5..42570751fc 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -118,6 +118,7 @@ private slots:
void colorInteger();
void invalidQColor();
+ void validQColor();
void debugStream_data();
void debugStream();
@@ -540,6 +541,21 @@ void tst_QGuiVariant::invalidQColor()
QVERIFY(!qvariant_cast<QColor>(va).isValid());
}
+void tst_QGuiVariant::validQColor()
+{
+ QColor col(Qt::red);
+ QVariant va(col.name());
+ QVERIFY(va.canConvert(QVariant::Color));
+
+ QVERIFY(va.convert(QVariant::Color));
+
+ QVERIFY(col.isValid());
+
+ QVERIFY(va.convert(QVariant::String));
+
+ QCOMPARE(qvariant_cast<QString>(va), col.name());
+}
+
void tst_QGuiVariant::colorInteger()
{
QVariant v = QColor(Qt::red);