Re: Problem sometimes connecting signal/slot in a loop

Kálmán Viktor <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CA+sJfQx_1aDPeC79KidgO7hyQUBe1yxbFMvfVz1xSRrvx_3g3A@mail.gmail.com>
It looks like you are running into this issue:
https://docs.python.org/2/faq/programming.html#why-do-lambdas-defined-in-a-loop-with-different-values-all-return-the-same-result

Luna Tuna <[email protected]> ezt írta (időpont: 2019. máj. 16.,
Cs, 23:43):

> Hi,
>
> Codes:
>
>     def setup(self):
>         for color in self._colors:
>             attr = color + ' color button'
>             attr = attr.replace(' ', '_')
>             button = getattr(self, attr)
>             self._buttons[color] = button
>             button.clicked.connect(lambda: self.show_color_dialog(color))
>
> When you do something like this, then all connections are made to the last
> color in the list,
> so clicking on "pen" color will always change "edit locked label" color
> (the last in list).
>
> I've fixed it before by making the connection in a dummy function.  But is
> there a better way to resolve this?
>
> Thanks.
>
> -Fruitful Approach
> _______________________________________________
> PyQt mailing list    [email protected]
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.