我试图让我的应用程序支持GUI中的多线程,我试图从GUI外的线程连接到GUI内的方法,我从
Simplest way for PyQT Threading
它被标记为有效解决方案,我的错在哪里
下面是错误。
class Communicate(QtCore.QObject):
myGUI_signal = QtCore.pyqtSignal(str)
def myThread(callbackFunc):
mySrc = Communicate()
mySrc.myGUI_signal.connect(callbackFunc)
while(True):
msgForGui = 'This is a message to send to the GUI'
mySrc.myGUI_signal.emit(msgForGui)
FORM_CLASS, _ = loadUiType(os.path.join(os.path.dirname('__file__'), "main.ui"))
class MainApp(QMainWindow, FORM_CLASS):
def __init__(self, parent=None):
super(MainApp, self).__init__(parent)
QMainWindow.__init__(self)
self.setupUi(self)
self.ui()
self.actions()
def ui(self):
self.setFixedSize(848, 663)
def actions(self):
self.pushButton.clicked.connect(self.startTheThread)
def theCallbackFunc(self, msg):
print('the thread has sent this message to the GUI:')
print(msg)
print('---------')
def startTheThread(self):
t = threading.Thread(name = 'myThread', target = myThread, args =(self.theCallbackFunc))
t.start()
def main():
app = QApplication(sys.argv)
window = MainApp()
window.show()
app.exec_()
if __name__ == '__main__':
main()