diff options
author | Erik Verbruggen <erik.verbruggen@digia.com> | 2016-01-27 12:08:18 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2016-01-27 12:17:53 +0000 |
commit | afbfdcff3b3cd14f16736b7c84e04fe9ad61ef8d (patch) | |
tree | 6cc74d05a219e8a687607dbe8d52637955302e52 /tests | |
parent | e9a6c1d4e30d6adb2190d52bebb7fecd2b539e82 (diff) |
QML: do not wrap property values of type QVariant.
When reading a propety from a QGadget or a QObject, the values are
stored in a QVariant and later unwrapped/converted to the correct
JavaScript type. However, if the property value is a QVariant, it does
not need to wrap it (again) in a QVariant.
Change-Id: I633d3194f82b6032fc15d9994c4dee5e5609fd21
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index 58755927b5..04abe0bfcb 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -1493,6 +1493,7 @@ struct MyOffice { Q_PROPERTY(int chairs MEMBER m_chairs) Q_PROPERTY(MyDesk desk READ desk WRITE setDesk) + Q_PROPERTY(QVariant myThing READ myThing WRITE setMyThing) Q_GADGET public: MyOffice() : m_chairs(0) {} @@ -1500,8 +1501,12 @@ public: MyDesk desk() const { return m_desk; } void setDesk(const MyDesk &d) { m_desk = d; } + QVariant myThing() const { return m_myThing; } + void setMyThing(const QVariant &thingy) { m_myThing = thingy; } + int m_chairs; MyDesk m_desk; + QVariant m_myThing; }; Q_DECLARE_METATYPE(MyOffice) @@ -1513,6 +1518,11 @@ void tst_qqmlvaluetypes::customValueType() MyOffice cppOffice; cppOffice.m_chairs = 2; + QVariantMap m; + m.insert(QStringLiteral("hasChair"), false); + m.insert(QStringLiteral("textOnWhiteboard"), QStringLiteral("Blah blah")); + cppOffice.m_myThing = m; + QJSValue office = engine.toScriptValue(cppOffice); QCOMPARE(office.property("chairs").toInt(), 2); office.setProperty("chairs", 1); @@ -1530,6 +1540,14 @@ void tst_qqmlvaluetypes::customValueType() cppOffice = engine.fromScriptValue<MyOffice>(office); QCOMPARE(cppOffice.m_chairs, 1); QCOMPARE(cppOffice.desk().monitorCount, 2); + + QJSValue thingy = office.property("myThing"); + QVERIFY(thingy.hasProperty("hasChair")); + QVERIFY(thingy.property("hasChair").isBool()); + QCOMPARE(thingy.property("hasChair").toBool(), false); + QVERIFY(thingy.property("textOnWhiteboard").isString()); + QVERIFY(thingy.hasProperty("textOnWhiteboard")); + QCOMPARE(thingy.property("textOnWhiteboard").toString(), QStringLiteral("Blah blah")); } struct BaseGadget |