<HTML>
<HEAD>
<TITLE>Re: [PyQt] lambda slot problem</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>You are seeing a scoping issue, to be safe, I would write the lambda as follows<BR>
<BR>
lambda changeStatus=self.changeStatus,m=msg,a=activated: changeStatus(m,a)<BR>
<BR>
This ensures that the bindings of self, activated and msg are what you expect when the lambda function is executed.<BR>
<BR>
On 4/2/09 7:16 PM, "Linos" <<a href="info@linos.es">info@linos.es</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Hello,<BR>
i suppose i am making any mistake here but i dont know why, for example:<BR>
<BR>
for checkbox, msg in ((self.printedCheckBox, "printed"), (self.finishedCheckBox,<BR>
"finished")):<BR>
self.connect(checkbox, SIGNAL("clicked(bool)"), lambda activated:<BR>
self.changeStatus(msg, activated))<BR>
<BR>
This one ever passes the last msg, "finished", although the checkbox<BR>
self.printedCheckBox is checked.<BR>
<BR>
self.connect(checkbox, SIGNAL("clicked(bool)"),<BR>
functools.partial(self.changeStatus, msg) works ok, why the lambda it is only<BR>
using the last msg string ever?<BR>
<BR>
Regards,<BR>
Miguel Angel.<BR>
_______________________________________________<BR>
PyQt mailing list <a href="PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a><BR>
<a href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><BR>
<BR>
</SPAN></FONT></BLOCKQUOTE>
</BODY>
</HTML>