[PyKDE] Disconnecting Python signals
Boudewijn Rempt
bsarempt at xs4all.nl
Mon May 14 21:51:57 BST 2001
I think I might have found a bug. It seems to be possible to disconnect
C++ signals and slots, but disconnecting Python signals and slots doesn't
work - it failes with
Traceback (most recent call last):
File "qobject.py", line 16, in timerEvent
self.emit(PYSIGNAL("timeSignal"), (self.counter,))
File "qobject.py", line 32, in slotTimeSignal
self.emit(PYSIGNAL("timeUp"), ())
File "qobject.py", line 52, in slotDisconnect
self.receiver.slotTimeSignal)
TypeError: Argument 4 of QObject.disconnect() has an invalid type
on the slot parameter. This is my test script:
#
# qobject.py = connect, disconnect and block signals
#
import sys
from qt import *
class EmittingObject(QObject):
def __init__(self, *args):
apply(QObject.__init__, (self, ) + args)
self.counter=0
self.timer = self.startTimer(100)
def timerEvent(self, ev):
self.counter+=1
self.emit(PYSIGNAL("timeSignal"), (self.counter,))
if self.counter == 20:
self.killTimer(self.timer)
def disconnectNotify(self, signal):
print "disconnected: ", signal
class ReceivingObject(QObject):
def __init__(self, *args):
apply(QObject.__init__, (self, ) + args)
def slotTimeSignal(self, count):
print count
if count == 10:
self.emit(PYSIGNAL("timeUp"), ())
class AppObject(QApplication):
def __init__(self, *args):
apply(QApplication.__init__, (self, ) + args)
self.emitter=EmittingObject(self)
self.receiver=ReceivingObject(self)
QObject.connect(self.emitter, PYSIGNAL("timeSignal"),
self.receiver.slotTimeSignal)
QObject.connect(self.receiver, PYSIGNAL("timeUp"),
self.slotDisconnect)
QObject.connect(self.receiver, SIGNAL("destroyed()"), self,
SLOT("quit()"))
QObject.disconnect(self.receiver, SIGNAL("destroyed()"), self,SLOT("quit()"))
def slotDisconnect(self):
self.disconnect(self.emitter,
PYSIGNAL("timeSignal"),
self.receiver,
self.receiver.slotTimeSignal)
def main(args):
app=AppObject(args)
app.exec_loop()
if __name__=="__main__":
main(sys.argv)
More information about the PyQt
mailing list