I have a PyQt widget that sends signals with
numpy.ndarray data. And I have another PyQt widget that has a slot with
Both widget are located on my main window, that is compiled from *.ui file. The widgets are set as promoted widgets.
Cannot I somehow connect the signal and slot in Qt Creator?
Just now it gives me the next error:
TypeError: C++ type 'ndarray' is not supported as a slot argument typeAnswer1:
Reason for this is Qt only support the datatype defined in QMetaType passed as argument of signal, looks here <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qmetatype.html#Q_DECLARE_METATYPE" rel="nofollow">http://pyqt.sourceforge.net/Docs/PyQt4/qmetatype.html#Q_DECLARE_METATYPE</a> According to ekhumoro's POST, I update the following code, it should work for PyQt4, not tested on PyQt5.
from PyQt4.QtGui import * from PyQt4.QtCore import * from numpy import * class MyThread(QThread): mysignal = pyqtSignal(ndarray) def __init__(self, parent=None): super(MyThread, self).__init__(parent) def run(self): while True: QThread.msleep(100) self.mysignal.emit(array((1, 2, 3, 4))) class MyWidget(QWidget): def __init__(self, parent=None): super(MyWidget, self).__init__(parent) self.thread = MyThread() self.thread.mysignal.connect(self.handleSignal) self.thread.start() def handleSignal(self, data): print data if __name__ == '__main__': import sys app = QApplication(sys.argv) w = MyWidget() w.show() app.exec_()