Details
Description
This is a regression in PySide6 6.5.1; the issue does not occur in 6.5.0.
In 6.5.1, if you connect signals to separate instances of an inner function, the connection will actually use the first instance of that inner function.
In other words, all connections to an inner function will reuse the variables that were captured the first time we instantiated the inner function. This leads to incorrect behavior when the signal is emitted, because the function acts on the wrong set of variables.
In the snippet below, clicking a button is supposed to change the text in the same button.
- In 6.5.0, this works fine;
- In 6.5.1, Button2 and Button3 change Button1's text instead of their own.
def connectPressed(button: QPushButton, text: str): def innerFunc(): button.setText(text) button.pressed.connect(innerFunc) button1 = QPushButton("Button1") button2 = QPushButton("Button2") button3 = QPushButton("Button3") connectPressed(button1, "You clicked Button1") connectPressed(button2, "You clicked Button2") connectPressed(button3, "You clicked Button3")
Note that the same behavior can be observed if connectPressed uses a lambda:
def connectPressed(button: QPushButton, text: str): button.pressed.connect(lambda: button.setText(text))
Attachments
Issue Links
- is duplicated by
-
PYSIDE-2348 PySide6: Wrong slot called in unit test after updating from 6.5.0 to 6.5.1
- Closed
-
PYSIDE-2355 Repeated QTimer.singleShot() reuses values captured previously
- Closed
-
PYSIDE-2356 Functor not working as target of connect in a loop
- Closed
-
PYSIDE-2358 bound method in value changed signal being substituted
- Closed
- resulted from
-
PYSIDE-2299 REG->6.5: Memory/Reference Leak with connecting signals to lambda functions referencing "self"
- Closed
For Gerrit Dashboard: PYSIDE-2346 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
481498,2 | Revert anonymous slot memory leak fix | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
481535,2 | Revert anonymous slot memory leak fix | 6.5 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
481577,3 | Revert anonymous slot memory leak fix | 6.5.1 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
481684,2 | Revert anonymous slot memory leak fix | tqtc/6.5.1 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |