How to disconnect a signal from a slot which is a lambda?

pyqt, python

Solution

No, it's because the two lambdas are not the same object.

You need to pass the same reference to the `disconnect` method you used in the `connect` method. If you use an anonymous lambda function, there is no way to disconnect it other then calling `disconnect()` (whithout arguments) on the signal, but that will disconnect all connected signals.

Problem

Suppose the slot takes an argument, e.g., ``` self._nam = QtNetwork.QNetworkAccessManager(self) # ... response = self._nam.get(request) self.timer.timeout.connect(lambda: self.on_reply_finished(response)) ``` How could the signal be disconnected from the slot? The following gives an error `Failed to disconnect signal timeout().`: ``` self.timer.timeout.disconnect(lambda: self.on_reply_finished(response)) ``` Is it because the lambda isn't a 'real' slot but a Python trick? In that case, how could the response argument be passed to the slot (without making `response` a member)? Thanks

Original source

Related problems