Hi i have send to my Thread worker link to GUI and update GUI info directly from QThread. Like here:
class Worker(QThread):
def __init__(self, ui):
QThread.__init__(self)
self.running = False
self.ui = ui
def run(self):
self.running = True
while self.running:
info = self.check_info()
rows = len(info)
self.ui.tableWidget.setRowCount(rows)
self.ui.tableWidget.setColumnCount(6)
...
In main QMainWindow
i just add
def __init__(self, parent=None):
.......
self.myworker = Worker(self.ui)
.....
Is such solution very bad in PyQt5? I am new in PyQt. Thx. If my solution is bad plz help me to fix it.
You can not and can not update the GUI from a secondary thread, you must do it through signals and slots:
For this we are going to create a signal through the class
pyqtSignal()
, and we will indicate the types of arguments, then we connect it to the slot that we want, as I show below:Thread:
GUI: