In QML, in some situations, I need to remove the old method to a signal and redefine a new method to handle the signal, a demo is as following:
import QtQuic
You can't disconnect the default signal handler onSignal: { do what ever }
.
You can only dissconnect, when you have connected with onSignal.connect(say)
beforehand. You could do this in Component.onCompleted
.
If you use the syntax:
onSignal: say()
this equals
onSignal.connect(function() { say() })
and therefore you can't use onSignal.disconnect(say)
as say
was never connected. (I don't know whether it is connected to onSignal
or to signal
- both could be done manually, or whether it is not connected at all. You can't disconnect it, without having a reference to the implicitly created function.)
In QML, the nicer way would be to stay declarative. For this you can use the Connections-construct:
Connections {
target: mouse // set to null to disconnect (Qt<=5.6)
onClicked: { do what ever }
enabled: true // change this, when you want to disconnect it (Qt>=5.7)
}