[PyKDE] slots and callables.
Phil Thompson
phil at river-bank.demon.co.uk
Wed May 30 21:49:38 BST 2001
>===== Original Message From Toby Sargeant <t.sargeant at inpharmatica.co.uk>
=====
>does anyone know why it seems that although you can use functions and bound
>methods as slots, you can't use other types of callable?
>
>import qt
>
>class Callable:
> def __init__(self,callable):
> self.callable=callable
> def __call__(self,*args,**kw):
> self.callable(*args,**kw)
>
>def f():
> print "foo"
>
>app=qt.QApplication([])
>box=qt.QLineEdit(None)
>box.show()
>
>box.connect(box,qt.SIGNAL('textChanged(const QString &)'),Callable(f))
>box.connect(box,qt.SIGNAL('textChanged(const QString &)'),Callable(lambda:f))
>box.connect(box,qt.SIGNAL('textChanged(const QString &)'),lambda:f)
>box.connect(box,qt.SIGNAL('textChanged(const QString &)'),f)
>
>app.setMainWidget(box)
>app.exec_loop()
>
>-- of the four connects, only the last works, even though the three prior to
>it are functionally equivalent. being able to use lambdas at least would be
>very handy. As an example, say you wanted to synchronize the position of
>a group of tables.
In the first 3 you are not keeping a reference to the callable live, so it
quietly gets deleted.
Phil
More information about the PyQt
mailing list