From ac57f185d1a2203cd4b585df7bd7af01c3ec33ed Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Fri, 28 Feb 2014 16:01:53 +0100 Subject: Fix calls to overloaded slots for QObjects not created by QML If we don't have a property cache, we need to fall back to a slower method of determining the overload methods. We have the code for that in RelatedMethod, once we determine that we're calling overloads, but we never hit that code path because we did not _initially_ determine that the method was an overload. Task-number: QTBUG-37157 Change-Id: I8ff39156e5668236b3797400b4086ed545624398 Reviewed-by: Lars Knoll --- tests/auto/qml/qjsengine/tst_qjsengine.cpp | 68 ++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'tests/auto/qml/qjsengine/tst_qjsengine.cpp') diff --git a/tests/auto/qml/qjsengine/tst_qjsengine.cpp b/tests/auto/qml/qjsengine/tst_qjsengine.cpp index bb5f83bed1..f5046395dd 100644 --- a/tests/auto/qml/qjsengine/tst_qjsengine.cpp +++ b/tests/auto/qml/qjsengine/tst_qjsengine.cpp @@ -69,6 +69,7 @@ public: virtual ~tst_QJSEngine(); private slots: + void callQObjectSlot(); void constructWithParent(); void newObject(); void newArray(); @@ -160,6 +161,73 @@ tst_QJSEngine::~tst_QJSEngine() { } +class OverloadedSlots : public QObject +{ + Q_OBJECT +public: + OverloadedSlots() + { + } + +signals: + void slotWithoutArgCalled(); + void slotWithSingleArgCalled(const QString &arg); + void slotWithArgumentsCalled(const QString &arg1, const QString &arg2, const QString &arg3); + +public slots: + void slotToCall() { emit slotWithoutArgCalled(); } + void slotToCall(const QString &arg) { emit slotWithSingleArgCalled(arg); } + void slotToCall(const QString &arg, const QString &arg2, const QString &arg3 = QString()) + { + slotWithArgumentsCalled(arg, arg2, arg3); + } +}; + +void tst_QJSEngine::callQObjectSlot() +{ + OverloadedSlots dummy; + QJSEngine eng; + eng.globalObject().setProperty("dummy", eng.newQObject(&dummy)); + QQmlEngine::setObjectOwnership(&dummy, QQmlEngine::CppOwnership); + + { + QSignalSpy spy(&dummy, SIGNAL(slotWithoutArgCalled())); + eng.evaluate("dummy.slotToCall();"); + QCOMPARE(spy.count(), 1); + } + + { + QSignalSpy spy(&dummy, SIGNAL(slotWithSingleArgCalled(QString))); + eng.evaluate("dummy.slotToCall('arg');"); + + QCOMPARE(spy.count(), 1); + const QList arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).toString(), QString("arg")); + } + + { + QSignalSpy spy(&dummy, SIGNAL(slotWithArgumentsCalled(QString, QString, QString))); + eng.evaluate("dummy.slotToCall('arg', 'arg2');"); + QCOMPARE(spy.count(), 1); + + const QList arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).toString(), QString("arg")); + QCOMPARE(arguments.at(1).toString(), QString("arg2")); + QCOMPARE(arguments.at(2).toString(), QString()); + } + + { + QSignalSpy spy(&dummy, SIGNAL(slotWithArgumentsCalled(QString, QString, QString))); + eng.evaluate("dummy.slotToCall('arg', 'arg2', 'arg3');"); + QCOMPARE(spy.count(), 1); + + const QList arguments = spy.takeFirst(); + QCOMPARE(arguments.at(0).toString(), QString("arg")); + QCOMPARE(arguments.at(1).toString(), QString("arg2")); + QCOMPARE(arguments.at(2).toString(), QString("arg3")); + } +} + void tst_QJSEngine::constructWithParent() { QPointer ptr; -- cgit v1.2.3