Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given a pyqtBoundSignal how to determine the slot?

Given the signal, how can I determine the slot that a particular signal is connected to?

I am familiar with how to connect signal and slots, this is more for debugging purposes.

I am using pyqt5, python 2.7

like image 611
mingxiao Avatar asked Feb 13 '23 10:02

mingxiao


1 Answers

There is no such thing as "the" slot, because a signal can be connected to multiple slots, or multiple other signals, or the same signal/slot multiple times. But in any case, there is no built-in API that can list all the current connections.

You can get a count of the current connections for a signal, like this:

    count = button.receivers(button.clicked)

There is also connectNotify and disconnectNotify - but that doesn't get you much further, because reimplementing those methods will only tell you which signals were connected or disconnected for the object.

The QtTest module has QSignalSpy (only available in PyQt5), which can record all the emissions of a given signal. But, again, that will only give you the arguments that were sent, rather than where they were sent to.

I suppose the reason why Qt doesn't provide an API for this is that the list of connected items is potentially very volatile.

PS:

I forgot to mention dumpObjectInfo, which apparently does what you're asking for, but will only work with a debug build of Qt - for release builds, it does nothing.

like image 152
ekhumoro Avatar answered Feb 16 '23 03:02

ekhumoro