From pykde Sun Jun 25 20:42:35 2006 From: Phil Thompson Date: Sun, 25 Jun 2006 20:42:35 +0000 To: pykde Subject: Re: [PyKDE] PyQt4 signals and closures Message-Id: <200606252142.35862.phil () riverbankcomputing ! co ! uk> X-MARC-Message: https://marc.info/?l=pykde&m=115126835321714 On Sunday 25 June 2006 6:49 pm, Carlos Scheidegger wrote: > Hi everyone, > > I'm experimenting with PyQt4 signals. According to the documentation, > any Python callable can be used as a slot. However, I can't get > closures to work as I would expect them to. Here's some sample code > that exercises the situation: > > from PyQt4 import QtCore > > #!/usr/bin/env python > > class A(QtCore.QObject): > def __init__(self): > QtCore.QObject.__init__(self) > def makeClosure(self, x): > def f(): > print x > return f > > a = A() > a.connect(a, QtCore.SIGNAL("testClosure"), a.makeClosure(5)) > > a.makeClosure(6)() > > a.emit(QtCore.SIGNAL("testClosure")) > > Executing this only prints "6" to stdout on my Intel MacBook running > PyQt4. > > PyQt4 version: mac-gpl-snapshot-20060604 > sip version: sip-snapshot-20060525 > Qt version: 4.1.3 > > Is this a known issue? If any more info is needed to reproduce this, > let me know. connect() does not take a reference to a slot, so your closure is getting garbage collected immediately. Phil _______________________________________________ PyKDE mailing list PyKDE@mats.imk.fraunhofer.de http://mats.imk.fraunhofer.de/mailman/listinfo/pykde