开发者

PyQt_PyObject equivalent when using new-style signals/slots?

开发者 https://www.devze.com 2023-01-16 18:46 出处:网络
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:

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开发者_StackOverflow = 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?


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.


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)
0

精彩评论

暂无评论...
验证码 换一张
取 消