diff options
author | Milian Wolff <milian.wolff@kdab.com> | 2019-03-22 10:47:29 +0100 |
---|---|---|
committer | Frederik Gladhorn <frederik.gladhorn@qt.io> | 2019-03-25 12:28:51 +0000 |
commit | 857cfc1adecd72750cea26d4c91371f4aaf9a68f (patch) | |
tree | a0c9e9b0822efbd390a4db83957ad02ccfbb6307 | |
parent | 8b701450aeceb878784879eaf65dc42d5befd3a5 (diff) | |
download | qtwebchannel-857cfc1adecd72750cea26d4c91371f4aaf9a68f.tar.gz |
Only connect to signal once per client object
We only disconnect once when all signals are disconnected, so we
should also only connect at most once per signal.
Change-Id: Ib3a866c3942bec5e06e3b301315bc83cdb972fab
Reviewed-by: Arno Rehn <a.rehn@menlosystems.com>
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r-- | examples/webchannel/shared/qwebchannel.js | 13 | ||||
-rw-r--r-- | tests/auto/qml/tst_webchannel.qml | 25 |
2 files changed, 35 insertions, 3 deletions
diff --git a/examples/webchannel/shared/qwebchannel.js b/examples/webchannel/shared/qwebchannel.js index d75e148..1e0d72a 100644 --- a/examples/webchannel/shared/qwebchannel.js +++ b/examples/webchannel/shared/qwebchannel.js @@ -261,9 +261,16 @@ function QObject(name, data, webChannel) object.__objectSignals__[signalIndex] = object.__objectSignals__[signalIndex] || []; object.__objectSignals__[signalIndex].push(callback); - if (!isPropertyNotifySignal && signalName !== "destroyed") { - // only required for "pure" signals, handled separately for properties in propertyUpdate - // also note that we always get notified about the destroyed signal + // only required for "pure" signals, handled separately for properties in propertyUpdate + if (isPropertyNotifySignal) + return; + + // also note that we always get notified about the destroyed signal + if (signalName === "destroyed") + return; + + // and otherwise we only need to be connected only once + if (object.__objectSignals__[signalIndex].length == 1) { webChannel.exec({ type: QWebChannelMessageTypes.connectToSignal, object: object.__id__, diff --git a/tests/auto/qml/tst_webchannel.qml b/tests/auto/qml/tst_webchannel.qml index 298376f..0069261 100644 --- a/tests/auto/qml/tst_webchannel.qml +++ b/tests/auto/qml/tst_webchannel.qml @@ -451,4 +451,29 @@ TestCase { 0 ]); } + + function test_multiConnect() + { + var signalArgs = []; + function logSignalArgs(arg) { + signalArgs.push(arg); + } + var channel = client.createChannel(function(channel) { + var testObject = channel.objects.testObject; + testObject.testSignalInt.connect(logSignalArgs); + testObject.testSignalInt.connect(logSignalArgs); + testObject.triggerSignals(); + }); + client.awaitInit(); + + var msg = client.awaitMessage(); + compare(msg.type, JSClient.QWebChannelMessageTypes.connectToSignal); + compare(msg.object, "testObject"); + + msg = client.awaitMessage(); + compare(msg.type, JSClient.QWebChannelMessageTypes.invokeMethod); + client.awaitIdle(); + + compare(signalArgs, [42, 42, 1, 1, 0, 0]); + } } |