Question

I have a widget in Pyside that is connected to a receiver. This receiver is generated using lambda like functionality.Some where later, I would like to retrieve the function pointer, disconnect it, do some stuff and the reconnect it. Is this doable?

    def GenVolCallbacks(RList,foo):
        def callme(hest):
            self.SliderChanged(RList,foo)
        return callme

....

x[-1].valueChanged.connect(GenVolCallbacks(x,foo))

Then some where I would like to do something like

Fpointer = x[-1].valueChanged.connectedReceiver()
x[-1].valueChanged.disConnect(Fpointer)
AlotOfProcessing()
x[-1].valueChanged.connect(Fpointer)
Was it helpful?

Solution

No, this is not possible.

To start with, a signal can be connected to many different slots (as well as other signals). So even if Qt provided an API for retrieving the list of the receivers a signal is connected to (which it doesn't), you would still need to have some way of selecting the specific receiver you were interested in That is, you would need to know the name of it beforehand, or already have a reference to it.

So keeping your own reference to the receiver is your only option. Or to put it another way: if you want to disconnect/reconnect a signal, don't connect it to an anonymous callable...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top