Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
522 views
in Technique[技术] by (71.8m points)

pyqt - PyQt_PyObject equivalent when using new-style signals/slots?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...