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 haven't used the explicit connect()
function to begin with. To disconnect()
a function, it has to have been connected explicitly using connect()
.
There is an example here that might help:
http://doc.qt.io/qt-5/qtqml-syntax-signals.html#connecting-signals-to-methods-and-signals
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)
}