By reading this, two questions came up:
1. It says
it is sometimes necessary to explicitly mark a Python method as being a Qt slot
While I always use the @pyqtSlot decorator because it says:
Connecting a signal to a decorated Python method also has the advantage of reducing the amount of memory used and is slightly faster
I ask myself: in which specific cases is it necessary? and: Are there any advantages of not using the @pyqtSlot decorator?
2. The result keyword argument, what is its purpose?
@pyqtSlot(int, result=int)
def foo(self, arg1):
""" C++: int foo(int) """
It looks like the return value's type, but AFAIK you cannot retrieve return values when emitting signals.
Any ideas about that?
It is faster because of PyQt architecture. PyQt converts the python slots to C++ slots, in order to communicate with the Qt framework. When you explicitly mark a Python method as a Qt slot and provide a C++ signature for it, the PyQt code doesn't have to guess the C++ signature itself, as it is already specified. This may enhance performance on heavy projects.
The return value is only needed when you want to call the slot as a normal function.
Edit: It seems that the QMetaObject.invokeMethod
method executes a slot and uses it's return value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With