PyQt4 @pyqtSlot: what is kwarg for?

After reading this , two questions appeared:

1. It says:

sometimes it is necessary to explicitly mark a Python method as a Qt slot

Although I always use the @pyqtSlot decorator because it says:

Connecting a signal to a decorated Python method also has the advantage of reducing memory usage and is slightly faster

I ask myself: in what specific cases is this necessary? and: Are there any advantages to using the @pyqtSlot decoder?

2. The keyword argument of the result, what is its purpose?

@pyqtSlot(int, result=int) def foo(self, arg1): """ C++: int foo(int) """ 

It looks like a return type, but AFAIK you cannot get return values ​​when emitting signals.

Any ideas on this?

+6
source share
1 answer
  • This is faster due to PyQt architecture. PyQt converts python slots to C ++ slots to communicate with a Qt map. When you explicitly mark a Python method as a Qt slot and provide it with a C ++ signature, PyQt code should not guess the C ++ signature itself, as already indicated. This can increase productivity on heavy projects.

  • The return value is only required when you want to call the slot as a regular function.

Change It seems that the QMetaObject.invokeMethod method executes the slot and uses its return value.

+6
source

Source: https://habr.com/ru/post/919380/


All Articles