diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2023-10-17 10:01:04 +0800 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-11-11 10:46:06 +0000 |
commit | 70ac45623b8305a222397affdbf4865275195703 (patch) | |
tree | 5ecf32deb7ce93c4b16b1fd7844444e8d66b4e2d | |
parent | 5f860b78646b7ab9490187186d3a58d8365359b7 (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.5 6.2
Change-Id: I76aaffba114a6db5b5aab6a2ff58541aa3b2e025
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit fd7459a60c3b396984c948f244ec0996fba56837)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/qmltest/SignalSpy.qml | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/qmltest/SignalSpy.qml b/src/qmltest/SignalSpy.qml index dd6c8ec892..ca92f91138 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 } |