Should I decorate slots in Pyside2 and if so how?
Example code of 2 different slots:
buttonTriggered = QAction('Button Triggered', self)
buttonToggled = QAction('Button Toggled', self)
buttonToggled.toggled.connect(lambda checked: self.onButtonToggled(checked))
def onButtonToggled(self, checked):
Hi RaSt welcome to the forum. You can decorate PySide2 slots the same way you do for PyQt5, just using the decorator
from PySide2.QtCore import Slot
from PyQt5.QtCore import pyqtSlot
As to whether you should decorate the slots, it’s a little trickier to answer – but generally speaking no, you don’t need to.
The only place I know the slot decorator is needed is when a) using threads, as it ensures the decorated method is started in the correct thread, or b) when you want to explicitly map a given slot to a specific call signature (types) in C++.
In your examples, the slots are running in the GUI thread and signal/slots are single-typed, so you don’t need them.
hi martin, thanks for your answer.
so I won’t do it