I was trying to write a slot that connects to different pyqt signals. What I still can't wrap my head around is the difference between the two decorators @pyqtSignature() and @pyqtSlot().
Example to connect to pyqt clicked signal of QPushButton which is inherited from QAbstractButton, I used the following syntax on_widgetName_signalName
, when using @pyqtSignature(""):
@pyqtSignature("")
def on_bn_gpx_select_file_clicked(self):
"""
Run when QPushButton is pressed, or do something
"""
pass
Now when using @pyqtSlot()
@pyqtSlot()
def on_bn_gpx_select_file_clicked(self):
"""
Run when QPushButton is pressed, or do something
"""
pass
My question is, what is the difference between the two decorators and when should I use @pyqtSignature or @pyqtSlot()
Thanks
The pyqtSignature
decorator is part of the old-style signal and slot syntax, which was replaced by the new-style signal and slot syntax in PyQt-4.5.
Both decorators serve the same purpose, which is to explicitly mark a python method as a Qt slot and specify a C++ signature for it (most commonly in order to select a particular overload). The only relevant difference between the two decorators is that pyqtSlot
has a much more pythonic API.
There should never be any need to use pyqtSignature
in new code - it is only really needed for backwards-compatibility.