diff options
author | Nils Jeisecke <nils.jeisecke@saltation.com> | 2018-03-02 17:34:23 +0100 |
---|---|---|
committer | Nils Jeisecke <nils.jeisecke@saltation.com> | 2018-03-14 11:17:07 +0000 |
commit | 1b996c138f6afae7ccf9d9ec87036768fd8ef329 (patch) | |
tree | efbfb520f8ff58264dfe4250c975c5419b075aff /tests/auto/qml/qqmlvaluetypes | |
parent | 44e37e7c213d4f472450b0d4ca673eb7c7e57122 (diff) |
tests: add autotest for Q_GADGET derived template class
This tests the effectivity of the qtbase fixes for QTBUG-66744.
Task-number: QTBUG-66744
Change-Id: I5bb041082ae4ce6cb91076c3f1279ac7bdcae4f0
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlvaluetypes')
-rw-r--r-- | tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp index c252bba001..a456facd2f 100644 --- a/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp +++ b/tests/auto/qml/qqmlvaluetypes/tst_qqmlvaluetypes.cpp @@ -89,6 +89,7 @@ private slots: void customValueType(); void customValueTypeInQml(); void gadgetInheritance(); + void gadgetTemplateInheritance(); void toStringConversion(); void enumerableProperties(); void enumProperties(); @@ -1613,6 +1614,19 @@ public: Q_INVOKABLE void functionInDerivedGadget(int value) { m_derivedProperty = value; } }; +// QTBUG-66744: we want a Q_GADGET giving us generic type safety in C++ and property access in Qml +template <typename T> +struct DerivedTypedGadget : public BaseGadget +{ + // cannot use Q_GADGET here +public: + DerivedTypedGadget() {} +}; + +class DerivedTypedGadgetDummyType {}; + +Q_DECLARE_METATYPE(DerivedTypedGadget<DerivedTypedGadgetDummyType>) + class TypeWithCustomValueType : public QObject { Q_OBJECT @@ -1657,6 +1671,21 @@ void tst_qqmlvaluetypes::gadgetInheritance() QCOMPARE(value.property("baseProperty").toInt(), 42); } +void tst_qqmlvaluetypes::gadgetTemplateInheritance() +{ + QJSEngine engine; + + QJSValue value = engine.toScriptValue(DerivedTypedGadget<DerivedTypedGadgetDummyType>()); + + QCOMPARE(value.property("baseProperty").toInt(), 0); + value.setProperty("baseProperty", 10); + QCOMPARE(value.property("baseProperty").toInt(), 10); + + QJSValue method = value.property("functionInBaseGadget"); + method.call(QJSValueList() << QJSValue(42)); + QCOMPARE(value.property("baseProperty").toInt(), 42); +} + struct StringLessGadget { Q_GADGET }; |