Changing GUI directly from Qthread PyQt 5

Viewed 4138

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.

1 Answers
Related