[PyKDE] PyQt not refing slot methods

Rob W.W. Hooft rob at hooft.net
Mon Sep 2 13:31:01 BST 2002


Adding to an old discussion: It is not only for lambda's that it would
be nice if slot methods would be refcounted: I am consistently using a 
"Command" class myself for slot actions (see appended code). Creating a 
slot using "connect(....,MethodCommand(self.takeAction))" now requires 
the _lst hack....


_lst=[]

class Command:
     def __init__(self):
         _lst.append(self) # Qt doesn't keep a reference! Memory leak!

     def __call__(self,*args,**kw):
	try:
	    return self.Execute(*args,**kw)
	except KeyboardInterrupt:
	    pass

class MethodCommand(Command):
     def __init__(self,method):
	self.method=method
         Command.__init__(self)

     def Execute(self,*args,**kw):
	return self.method()

class MethodArgsCommand(Command):
     def __init__(self,method,*args,**kw):
         Command.__init__(self)
	self.method=method
	self.args=args
	self.kw=kw

     def Execute(self,*args,**kw):
	return self.method(*self.args,**self.kw)

-- 
Rob W.W. Hooft  ||  rob at hooft.net  ||  http://www.hooft.net/people/rob/




More information about the PyQt mailing list