>===== Original Message From Toby Sargeant <[EMAIL PROTECTED]> 
=====
>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


_______________________________________________
PyKDE mailing list    [EMAIL PROTECTED]
http://mats.gmd.de/mailman/listinfo/pykde

Reply via email to