diff options
author | Michael Bruning <michael.bruning@theqtcompany.com> | 2016-04-12 15:14:55 +0200 |
---|---|---|
committer | Michael BrĂ¼ning <michael.bruning@theqtcompany.com> | 2016-04-20 13:38:31 +0000 |
commit | 0b7c11e7c2bb457bff399fdec38d9cf266e89a86 (patch) | |
tree | ab2567e5bd48d406079bb9d57dafb6a333561a60 /tests | |
parent | 9c8dab537819f0d999e680490c2d125b8836cbbb (diff) |
Also match QJSValue conversion types in MatchScore.
This had the effect that overloaded methods were always mapped to the
wrong slot.
[ChangeLog][QtQml][Important Behavior Changes] When matching the method signature
of a invokable method to the slot in the metaobject, the matching function now
assigns the best match to a QJSValue if the parameter actually is a QJSValue. This
corrects the previous behavior, where QJSValue and int were given the same match score
even though QJSValue would have been the best match.
Task-number: QTBUG-51746
Change-Id: I906e7b006ee5af92ea760ed1625e5047aef123bf
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmlecmascript/testtypes.h | 2 | ||||
-rw-r--r-- | tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlecmascript/testtypes.h b/tests/auto/qml/qqmlecmascript/testtypes.h index 5603356ef0..4abf5fb167 100644 --- a/tests/auto/qml/qqmlecmascript/testtypes.h +++ b/tests/auto/qml/qqmlecmascript/testtypes.h @@ -795,6 +795,8 @@ public: Q_INVOKABLE void method_QObject(QObject *a) { invoke(13); m_actuals << qVariantFromValue(a); } Q_INVOKABLE void method_QScriptValue(QJSValue a) { invoke(14); m_actuals << qVariantFromValue(a); } Q_INVOKABLE void method_intQScriptValue(int a, QJSValue b) { invoke(15); m_actuals << a << qVariantFromValue(b); } + Q_INVOKABLE QJSValue method_intQJSValue(int a, QJSValue b) { invoke(29); m_actuals << a << qVariantFromValue(b); return b.call(); } + Q_INVOKABLE QJSValue method_intQJSValue(int a, int b) { m_actuals << a << b; return QJSValue();} // Should never be called. Q_INVOKABLE void method_overload(int a) { invoke(16); m_actuals << a; } Q_INVOKABLE void method_overload(int a, int b) { invoke(17); m_actuals << a << b; } diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp index a208bf5634..60fc8d0b90 100644 --- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp +++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp @@ -2942,6 +2942,18 @@ void tst_qqmlecmascript::callQtInvokables() QCOMPARE(o->error(), false); QCOMPARE(o->invoked(), -1); QCOMPARE(o->actuals().count(), 0); + + o->reset(); + QV4::ScopedValue ret(scope, EVALUATE("object.method_intQJSValue(123, function() { return \"Hello world!\";})")); + QCOMPARE(o->error(), false); + QCOMPARE(o->invoked(), 29); + QVERIFY(ret->isString()); + QCOMPARE(ret->toQStringNoThrow(), QString("Hello world!")); + QCOMPARE(o->actuals().count(), 2); + QCOMPARE(o->actuals().at(0), QVariant(123)); + QJSValue callback = qvariant_cast<QJSValue>(o->actuals().at(1)); + QVERIFY(!callback.isNull()); + QVERIFY(callback.isCallable()); } // QTBUG-13047 (check that you can pass registered object types as args) |