[PyQt] Re: multiple signal connect

Daniel Miller daniel at keystonewood.com
Thu Aug 21 13:17:33 BST 2008


>> < snip second buggy solution >
>
> So all I am seeing is that these things of anonymous/lambda functions
> are evil in Python, because of the lexical/binding thing...

Well lambda's are not evil per-se, although they do have a few  
quirks. Technically though, this:

g = lambda x: f(x)

is same as this

def g(x):
     return f(x)

lambdas just have a few limitations of what you can put in the body  
(i.e. only one expression, no statements).

> Anyway, your other email seems to have a better way of solving  
> this, and
> it's now working great. So thank you for your help :-)

I'm glad you got it working. I'm surprised that the first version  
actually worked--it should give you the same problem as your original  
solution. FWIW, my second version was buggy too, so here's the third  
attempt. I should probably refrain from posting untested code...

def make_slot(button):
     def slot():
         self.button_clicked(button)
     button.__slot = slot
     return slot # forgot this on the previous version

for button in [ ... ]:
     QtCore.QObject.connect( ... , make_slot(button))


~ Daniel



More information about the PyQt mailing list