[PyKDE] PyQt not refing slot methods - bug?

Burley, Brent Brent.Burley at disney.com
Thu Aug 29 21:04:01 BST 2002


I was trying to use a lambda method as a slot method like this:

import sys           
from qt import *
def hello(): print 'hello'
app = QApplication(sys.argv)
b = QPushButton('hello', None)
QObject.connect(b, SIGNAL('clicked()'), lambda: hello())
app.setMainWidget(b)
b.show()
app.exec_loop()


The lambda method never gets called.  It appears that PyQt doesn't ref slot methods so the lambda method gets deleted before it can be used.  If I change the code to keep a reference to the lambda, it works fine:

l = lambda: hello()
QObject.connect(b, SIGNAL('clicked()'), l)


Is it a bug that PyQt isn't refing slot methods?  Doesn't anyone use lambdas for slots?


Brent Burley 
brent.burley at disney.com




More information about the PyQt mailing list