aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmltest/SignalSpy.qml
diff options
context:
space:
mode:
Diffstat (limited to 'src/qmltest/SignalSpy.qml')
-rw-r--r--src/qmltest/SignalSpy.qml45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/qmltest/SignalSpy.qml b/src/qmltest/SignalSpy.qml
index dd6c8ec892..ea77a1704d 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 ? qttest_signalFunc(target, signalName) : null
+ if (signalFunc)
+ signalFunc.disconnect(spy.qtest_activated)
+ }
+
TestUtil {
id: util
}
@@ -191,8 +201,7 @@ Item {
qtest_reentrancy_guard = true;
if (qtest_prevTarget != null) {
- var prevHandlerName = qtest_signalHandlerName(qtest_prevSignalName)
- var prevFunc = qtest_prevTarget[prevHandlerName]
+ let prevFunc = qttest_signalFunc(qtest_prevTarget, qtest_prevSignalName)
if (prevFunc)
prevFunc.disconnect(spy.qtest_activated)
qtest_prevTarget = null
@@ -200,22 +209,16 @@ Item {
}
if (target != null && signalName != "") {
// Look for the signal name in the object
- var func = target[signalName]
- if (typeof func !== "function") {
- // If it is not a function, try looking for signal handler
- // i.e. (onSignal) this is needed for cases where there is a property
- // and a signal with the same name, e.g. Mousearea.pressed
- func = target[qtest_signalHandlerName(signalName)]
- }
- if (func === undefined) {
- spy.qtest_valid = false
- console.log("Signal '" + signalName + "' not found")
- } else {
+ let func = qttest_signalFunc(target, signalName)
+ if (func) {
qtest_prevTarget = target
qtest_prevSignalName = signalName
func.connect(spy.qtest_activated)
spy.qtest_valid = true
spy.qtest_signalArguments = []
+ } else {
+ spy.qtest_valid = false
+ console.log("Signal '" + signalName + "' not found")
}
} else {
spy.qtest_valid = false
@@ -232,8 +235,18 @@ Item {
/*! \internal */
function qtest_signalHandlerName(sn) {
- if (sn.substr(0, 2) === "on" && sn[2] === sn[2].toUpperCase())
- return sn
- return "on" + sn.substr(0, 1).toUpperCase() + sn.substr(1)
+ return util.signalHandlerName(sn)
+ }
+
+ /*! \internal */
+ function qttest_signalFunc(_target, _signalName) {
+ let signalFunc = _target[_signalName]
+ if (typeof signalFunc !== "function") {
+ // If it is not a function, try looking for signal handler
+ // i.e. (onSignal) this is needed for cases where there is a property
+ // and a signal with the same name, e.g. Mousearea.pressed
+ signalFunc = _target[qtest_signalHandlerName(_signalName)]
+ }
+ return signalFunc
}
}