[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyKDE] PyQt4 signals and closures
From:       Phil Thompson <phil () riverbankcomputing ! co ! uk>
Date:       2006-06-25 20:42:35
Message-ID: 200606252142.35862.phil () riverbankcomputing ! co ! uk
[Download RAW message or body]

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
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic