PyQt4 @pyqtSlot:kwarg 的结果是什么? [英] PyQt4 @pyqtSlot: what is the result kwarg for?
问题描述
通过阅读这篇,两个问题来了:
By reading this, two questions came up:
1.它说
有时需要将 Python 方法显式标记为一个 Qt 插槽
it is sometimes necessary to explicitly mark a Python method as being a Qt slot
虽然我总是使用 @pyqtSlot 装饰器,因为它说:
While I always use the @pyqtSlot decorator because it says:
将信号连接到修饰的 Python 方法也有减少内存使用量的优势,速度稍快
Connecting a signal to a decorated Python method also has the advantage of reducing the amount of memory used and is slightly faster
我问自己:在哪些特定情况下是必要的?以及:不使用 @pyqtSlot 装饰器有什么好处吗?
I ask myself: in which specific cases is it necessary? and: Are there any advantages of not using the @pyqtSlot decorator?
2.结果关键字参数,它的用途是什么?
2. The result keyword argument, what is its purpose?
@pyqtSlot(int, result=int)
def foo(self, arg1):
""" C++: int foo(int) """
它看起来像返回值的类型,但是AFAIK在发出信号时无法检索返回值.
It looks like the return value's type, but AFAIK you cannot retrieve return values when emitting signals.
对此有什么想法吗?
推荐答案
由于 PyQt 架构,速度更快.PyQt 将 python 插槽转换为 C++ 插槽,以便与 Qt 框架进行通信.当您将 Python 方法显式标记为 Qt 槽并为其提供 C++ 签名时,PyQt 代码不必猜测 C++ 签名本身,因为它已被指定.这可能会提高大型项目的性能.
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.
编辑:QMetaObject.invokeMethod
方法执行一个槽并使用它的返回值.
Edit: It seems that the QMetaObject.invokeMethod
method executes a slot and uses it's return value.
这篇关于PyQt4 @pyqtSlot:kwarg 的结果是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!