aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2023-10-17 10:01:04 +0800
committerMitch Curtis <mitch.curtis@qt.io>2023-11-10 16:15:28 +0800
commitfd7459a60c3b396984c948f244ec0996fba56837 (patch)
tree43a3376b39a1dbb18947a29c17acc8052f8021a5 /src/qmltest
parentad01abe1a62ea50d19cca2b4ccd799b9a01e3e12 (diff)
SignalSpy: manually disconnect from target signal when we're destroyed
The SignalSpy is potentially destroyed before the target object, and since only the sender (target) being destroyed destroys a connection in QML, and not the receiver (SignalSpy), we need to manually disconnect. When QTBUG-118166 is implemented, we can remove this. Task-number: QTBUG-118163 Pick-to: 6.2 6.5 6.6 Change-Id: I76aaffba114a6db5b5aab6a2ff58541aa3b2e025 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qmltest')
-rw-r--r--src/qmltest/SignalSpy.qml10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/qmltest/SignalSpy.qml b/src/qmltest/SignalSpy.qml
index 029003c70f..93fde00edb 100644
--- a/src/qmltest/SignalSpy.qml
+++ b/src/qmltest/SignalSpy.qml
@@ -45,6 +45,16 @@ Item {
id: spy
visible: false
+ Component.onDestruction: {
+ // We are potentially destroyed before the target object,
+ // and since only the sender (target) being destroyed destroys a connection
+ // in QML, and not the receiver (us/"spy"), we need to manually disconnect.
+ // When QTBUG-118166 is implemented, we can remove this.
+ let signalFunc = target ? target[signalName] : null
+ if (signalFunc)
+ signalFunc.disconnect(spy.qtest_activated)
+ }
+
TestUtil {
id: util
}