使用新型信号/槽时 PyQt_PyObject 等效吗?

发布于 2024-09-24 09:35:13 字数 339 浏览 3 评论 0原文

所以我需要在我的 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 using
self.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

难得心□动 2024-10-01 09:35:13

您正在寻找的类型是 np.ndarray
您可以从以下代码中看出这一点:

>>> arr = np.array([])  # create an array instance
>>> type(arr)           # ask 'what type is this object?'
<type 'numpy.ndarray'>

因此您的信号应该看起来更像:(

newChunkToProcess = pyqtSignal(np.ndarray)

请注意,我传递的是类型 np.ndarray,而不是您传递的数组实例尝试过)。
如果您不想担心参数的类型,您可以使用:

newChunkToProcess = pyqtSignal(object)

这应该让您可以通过信号发送任何数据类型。

另外:据我所知,numpy 和 Qt 不共享任何主要功能。事实上,两者非常互补,是一个非常强大的组合。

The type you're looking for is np.ndarray
You can tell this from the following code:

>>> arr = np.array([])  # create an array instance
>>> type(arr)           # ask 'what type is this object?'
<type 'numpy.ndarray'>

So your signal should look more like:

newChunkToProcess = pyqtSignal(np.ndarray)

(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:

newChunkToProcess = pyqtSignal(object)

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.

撩心不撩汉 2024-10-01 09:35:13

你做错了。您必须在案例列表中传递数据对象类型:int,str,...

就像我正在做的那样:

images = pyqtSignal(int, str);
failed = pyqtSignal(str, str);
finished = pyqtSignal(int)

You are doing it wrong. You have to pass the data object type: int, str, ... in your case list

Like I am doing:

images = pyqtSignal(int, str);
failed = pyqtSignal(str, str);
finished = pyqtSignal(int)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文