aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qjsengine/tst_qjsengine.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2014-02-28 16:01:53 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-02 22:29:51 +0100
commitac57f185d1a2203cd4b585df7bd7af01c3ec33ed (patch)
tree8e6d9a9c256db1e9f10e3bc0ef4f4d546ae6fcdb /tests/auto/qml/qjsengine/tst_qjsengine.cpp
parentb92b339705c9075a4b1b05b1b470827915dfe50d (diff)
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 <lars.knoll@digia.com>
Diffstat (limited to 'tests/auto/qml/qjsengine/tst_qjsengine.cpp')
-rw-r--r--tests/auto/qml/qjsengine/tst_qjsengine.cpp68
1 files changed, 68 insertions, 0 deletions
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<QVariant> 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<QVariant> 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<QVariant> 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<QJSEngine> ptr;