使用新型信号/槽时 PyQt_PyObject 等效吗?
所以我需要在我的 PyQt 应用程序中传递一个 numpy 数组。我首先尝试使用新型信号/槽,使用以下命令定义信号:
newChunkToProcess = pyqtSignal(np.array())
,但这给出了错误: TypeError: required argument 'object' (pos 1) not found
我已经弄清楚如何使用旧式信号和插槽来做到这一点 self.emit(SIGNAL("newChunkToProcess(PyQt_PyObject)"), np.array([5,1,2])) - (是的,这只是测试数据:),但我想知道,使用新型系统可以做到这一点吗?
So I have a need to pass around a numpy array in my PyQt Application. I first tried using the new-style signals/slots, defining my signal with:
newChunkToProcess = pyqtSignal(np.array())
, however this gives the error:
TypeError: Required argument 'object' (pos 1) not found
I have worked out how to do this with the old-style signals and slots usingself.emit(SIGNAL("newChunkToProcess(PyQt_PyObject)"), np.array([5,1,2]))
- (yes, that's just testing data :), but I was wondering, is it possible to do this using the new-style system?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在寻找的类型是 np.ndarray
您可以从以下代码中看出这一点:
因此您的信号应该看起来更像:(
请注意,我传递的是类型 np.ndarray,而不是您传递的数组实例尝试过)。
如果您不想担心参数的类型,您可以使用:
这应该让您可以通过信号发送任何数据类型。
另外:据我所知,numpy 和 Qt 不共享任何主要功能。事实上,两者非常互补,是一个非常强大的组合。
The type you're looking for is np.ndarray
You can tell this from the following code:
So your signal should look more like:
(Notice I'm passing the type np.ndarray, rather than an array instance as you tried).
If you don't want to worry about the type of the argument, you could instead use:
This should let you send any data type at all through the signal.
Also: numpy and Qt do not share any major functionality that I know of. In fact, the two are quite complementary and make a very powerful combination.
你做错了。您必须在案例列表中传递数据对象类型:int,str,...
就像我正在做的那样:
You are doing it wrong. You have to pass the data object type: int, str, ... in your case list
Like I am doing: