QMetaType: Fix conversion between module types.

Change-Id: I7215b4599c3f0459139b32b6571f0a9e60182ee9
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
bb10
Stephen Kelly 2013-11-02 17:31:12 +01:00 committed by The Qt Project
parent 417cf3fc53
commit 8ef5e700b8
2 changed files with 18 additions and 1 deletions

View File

@ -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;

View File

@ -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);