[PyQt] Hijacking QtCore.connect, disconnect and emit
cscheid at sci.utah.edu
Thu Jul 12 23:19:31 BST 2007
> Qt has builtin callbacks for signal slot debugging. I think you could use
> python's ctypes module to create python callbacks that would work. I don't
> have much experience with ctypes or using Qt's callbacks, so I can't provide
> any further details.
Thanks for the quick response. There is, in fact, QSignalSpy, but it doesn't
seem to be implemented in PyQt. Is there any reason for that?
In any case, I found a way around that. In case anyone is interested, here's
the final ugly solution:
_oldConnect = QtCore.QObject.connect
_oldDisconnect = QtCore.QObject.disconnect
_oldEmit = QtCore.QObject.emit
"""Returns a wrapped call to the old version of QtCore.QObject.connect"""
"""Returns a wrapped call to the old version of QtCore.QObject.disconnect"""
"""Call this to enable Qt Signal debugging. This will trap all
connect, and disconnect calls."""
f = lambda *args: None
connectCall = kwargs.get('connectCall', f)
disconnectCall = kwargs.get('disconnectCall', f)
emitCall = kwargs.get('emitCall', f)
print msg, args
QtCore.QObject.connect = _wrapConnect(connectCall)
QtCore.QObject.disconnect = _wrapDisconnect(disconnectCall)
def new_emit(self, *args):
QtCore.QObject.emit = new_emit
just call enableSignalDebugging(emitCall=foo) and spy your signals until
you're sick to your stomach :)
More information about the PyQt