diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2023-06-06 08:39:59 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2023-06-09 15:46:30 +0200 |
commit | fe8e388418608b4d07b3d8325915af05d386b993 (patch) | |
tree | 44613c79dcc0f7384c5073583576e5e91aaacf64 /tests/auto/qml/qqmlecmascript | |
parent | 38da583642529038c1d226f54946134a7261b654 (diff) |
QML: Fix overload resolution for QObject* types
Amazingly, QObject pointers were not supported at all so far.
Pick-to: 6.5 6.6
Change-Id: I61b28705d3bebf9602bdeee05aadcb085f39b184
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlecmascript')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs3.qml | 12 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 56 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 32 |
3 files changed, 89 insertions, 11 deletions
diff --git a/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs3.qml b/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs3.qml new file mode 100644 index 0000000000..a50c8e0f46 --- /dev/null +++ b/tests/auto/qml/qqmlecmascript/data/qmlTypeWrapperArgs3.qml @@ -0,0 +1,12 @@ +import QtQml +import Qt.test.singletonWithEnum + +QtObject { + id: root + required property QtObject invokableObject + + Component.onCompleted: { + root.invokableObject.method_typeWrapper(Component) + root.invokableObject.method_typeWrapper(SingletonWithEnum) + } +} diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index bc4d97237c..64c079a937 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -31,6 +31,7 @@ #include <private/qqmlengine_p.h> #include <private/qv4qobjectwrapper_p.h> +#include <private/qqmlcomponentattached_p.h> class MyQmlAttachedObject : public QObject { @@ -862,6 +863,17 @@ struct NonRegisteredType struct CompletelyUnknown; +class SingletonWithEnum : public QObject +{ + Q_OBJECT + Q_ENUMS(TestEnum) +public: + enum TestEnum { + TestValue = 42, + TestValue_MinusOne = -1 + }; +}; + class MyInvokableObject : public MyInvokableBaseObject { Q_OBJECT @@ -955,12 +967,43 @@ public: invoke(40); m_actuals << f; } + Q_INVOKABLE void method_qobject(QObject *o) { invoke(41); m_actuals << QVariant::fromValue(o); } + Q_INVOKABLE QQmlComponent *someComponent() { return &m_someComponent; } + Q_INVOKABLE void method_component(QQmlComponent *c) + { + invoke(42); + m_actuals << QVariant::fromValue(c); + } + + Q_INVOKABLE MyTypeObject *someTypeObject() { return &m_someTypeObject; } + Q_INVOKABLE void method_component(MyTypeObject *c) + { + invoke(43); + m_actuals << QVariant::fromValue(c); + } + + Q_INVOKABLE void method_component(const QUrl &c) + { + invoke(44); + m_actuals << QVariant::fromValue(c); + } + + Q_INVOKABLE void method_typeWrapper(QQmlComponentAttached *attached) + { + m_actuals << QVariant::fromValue(attached); + } + + Q_INVOKABLE void method_typeWrapper(SingletonWithEnum *singleton) + { + m_actuals << QVariant::fromValue(singleton); + } + private: friend class MyInvokableBaseObject; void invoke(int idx) { if (m_invoked != -1) m_invokedError = true; m_invoked = idx;} @@ -969,6 +1012,8 @@ private: QVariantList m_actuals; QFont m_someFont; + QQmlComponent m_someComponent; + MyTypeObject m_someTypeObject; public: Q_SIGNALS: @@ -1807,17 +1852,6 @@ public: QML_DECLARE_TYPEINFO(FallbackBindingsTypeObject, QML_HAS_ATTACHED_PROPERTIES) QML_DECLARE_TYPEINFO(FallbackBindingsTypeDerived, QML_HAS_ATTACHED_PROPERTIES) -class SingletonWithEnum : public QObject -{ - Q_OBJECT - Q_ENUMS(TestEnum) -public: - enum TestEnum { - TestValue = 42, - TestValue_MinusOne = -1 - }; -}; - // Like QtObject, but with default property class QObjectContainer : public QObject { diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index 2684157840..ab880957ac 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -3191,6 +3191,17 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->invoked(), -1); // no function got called due to incompatible arguments } + { + o->reset(); + QQmlComponent comp(&qmlengine, testFileUrl("qmlTypeWrapperArgs3.qml")); + QScopedPointer<QObject> root {comp.createWithInitialProperties({{"invokableObject", QVariant::fromValue(o)}}) }; + QVERIFY(root); + QCOMPARE(o->error(), false); + QCOMPARE(o->actuals().size(), 2); + QCOMPARE(o->actuals().at(0).metaType(), QMetaType::fromType<QQmlComponentAttached *>()); + QCOMPARE(o->actuals().at(1).metaType(), QMetaType::fromType<SingletonWithEnum *>()); + } + o->reset(); QVERIFY(EVALUATE_VALUE("object.method_QObject(undefined)", QV4::Primitive::undefinedValue())); QCOMPARE(o->error(), false); @@ -3522,6 +3533,27 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); QCOMPARE(o->actuals(), QVariantList()); + + o->reset(); + QVERIFY(EVALUATE_VALUE("object.method_component(object.someComponent())", + QV4::Primitive::undefinedValue())); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 42); + QCOMPARE(o->actuals(), QVariantList() << QVariant::fromValue(o->someComponent())); + + o->reset(); + QVERIFY(EVALUATE_VALUE("object.method_component(object.someTypeObject())", + QV4::Primitive::undefinedValue())); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 43); + QCOMPARE(o->actuals(), QVariantList() << QVariant::fromValue(o->someTypeObject())); + + o->reset(); + QVERIFY(EVALUATE_VALUE("object.method_component('qrc:/somewhere/else')", + QV4::Primitive::undefinedValue())); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 44); + QCOMPARE(o->actuals(), QVariantList() << QVariant::fromValue(QUrl("qrc:/somewhere/else"))); } void tst_qqmlecmascript::resolveClashingProperties() |