<div dir="ltr"><div><div><div><div><div><div><div>Working code in PyQt4, to connect signals from an array of QPushButtons:<br><br></div>    for j in range(number_of_buttons):<br></div>        self.connect(self.userButtons[j], SIGNAL("clicked()"),<br>

                                lambda b=j : self.user_button_click(b) )<br><br></div>This caused the clicked() signal of button j to invoke user_button_click() passing the value of j, i.e. the index to the clicked button.<br>

<br></div>Moving this code to the PyQt5 signal API:<br><br>    for j in range(number_of_buttons):<br>        self.user_buttons[j].clicked.connect(<br>                lambda b=j : self.user_button_click(b)<br>                )<br>

<br></div>The result is not as before. The user_button_click() method receives False from any button, not an int.<br><br>At first I thought -- oh, the signal is defined as "clicked(bool checked=False)" and so the checked property value is being passed. Even though the button is (by default) not checkable, somehow I am getting the clicked(bool) version instead of the clicked() overload.<br>

<br>But on second thought -- how could the signal's parameter get into the lambda expression, which made no reference to it?<br><br></div><div>If that is the case, what would be the modern API's version of SIGNAL('clicked()'), i.e. selecting a version of a signal that passes NO parameter?<br>

<br></div><div>Thanks for your thoughts,<br></div><div>Dave Cortesi<br><br></div><div><br></div></div></div>