Skip to content

Commit

Permalink
SignalSpy: manually disconnect from target signal when we're destroyed
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit fd7459a)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
  • Loading branch information
mitchcurtis authored and Qt Cherry-pick Bot committed Nov 11, 2023
1 parent 5f860b7 commit 70ac456
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/qmltest/SignalSpy.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 70ac456

Please sign in to comment.