Details
-
Bug
-
Resolution: Duplicate
-
Not Evaluated
-
None
-
6.5.1
-
None
-
Pyside 6.5.1
Description
Using a functor class as a target for connect in a loop
from sys import argv from sys import exit from PySide6.QtGui import QAction from PySide6.QtWidgets import QApplication from PySide6.QtWidgets import QMainWindow class PrintNum: def __init__(self, n): self.n = n def __call__(self): print(self.n) class MenuBar(QMainWindow): def __init__(self): super().__init__() menu = self.menuBar().addMenu("Num") for i in range(5): action = QAction(f"{i}", self) action.triggered.connect(PrintNum(i)) menu.addAction(action) app = QApplication(argv) menuBar = MenuBar() menuBar.show() exit(app.exec())
the first one will always be used. In this case for any selection always 0 is printed.
This worked in former Pyside6 versions and also works with PyQt.
Attachments
Issue Links
- duplicates
-
PYSIDE-2346 Connecting signal to inner function reuses first instance of inner function
- Closed