Dec-18-2020, 01:12 AM
Not sure to understand what you are doing exactly, but here is a threading example in PyQt5.
#!/usr/bin/python3 import time from PyQt5 import QtWidgets, QtCore class WorkerThread(QtCore.QObject): signalExample = QtCore.pyqtSignal(str, int) def __init__(self): super().__init__() @QtCore.pyqtSlot() def run(self): while True: # Long running task ... self.signalExample.emit("leet", 1337) time.sleep(5) class Main(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.worker = WorkerThread() self.workerThread = QtCore.QThread() # Move the Worker object to the Thread object self.workerThread.started.connect(self.worker.run) # Init worker run() at startup self.worker.moveToThread(self.workerThread) self.worker.signalExample.connect(self.signalExample) # Connect your signals/slots self.workerThread.start() def signalExample(self, text, number): print(text) print(number) if __name__ == '__main__': app = QtWidgets.QApplication([]) gui = Main() app.exec()