With Qt, I can filter all the QEvent
events my application receives or produces with:
qApp.installEventFilter(my_filter_object)
Is there any way to filter Qt signals (of signals and slots) in a similar manner I can filter QEvent
events?
With QtCore.QStateMachine.SignalEvent
extending QEvent
, and StateMachineSignal
QEvent.Type
being there, everything seems to be in place, but my event filter can't seem to catch one of these.
IOW, is there any way to get the signal's name (index), the signal emitting object, and the passed arguments, for each signal of every QObject
in my application without explicitly connecting to it?
Thanks!
No. The only generic API for monitoring signals is QSignalSpy, but that requires an explicit connection to a specific object and signal. The only other thing is the TestLib Framework, which has a command-line option (-vs
) that can output all the emitted signals during a test run. But that seems pretty far removed from what you're asking for.
Of course, you can use QMetaObject to list all the signals of a QObject
and try to explicitly monitor everything. But that presupposes you can get a reference to all the objects you might be interested in (and that you can actually know in advance what they will be).
The only exception to the above, is for signals that are emitted via a queued connection. These signals, which are most commonly emitted across threads, are wrapped in an event and posted to the event-queue of the receiver's thread. It is possible to detect these kinds of signals by filtering on events of type QEvent.MetaCall
.
However, the associated event objects are of type QMetaCallEvent
, which is an internal Qt class which is not wrapped by PyQt. Normally, these objects would have id()
, sender()
, signalId()
and args()
methods. But in PyQt, all you'll get is a plain QEvent
, and thus no information about the emitted signal will be available.
Even if QMetaCallEvent
was available, though, the default connection type is not queued - and there is no way to globally reset the default for all signals.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With