79127149

Date: 2024-10-25 19:55:38
Score: 0.5
Natty:
Report link

It is necessary to create a class inheriting from Qthread.

class RequestThread(QThread):
def __init__(self, mainwindow, parent=None):
    super().__init__()
    # print('created qthread')
    # self.mainwindow = mainwindow

def run(self):
    value = self.mainwindow.number1
    this insert request  function

    while value < 100:
        time.sleep(0.1)

        value = value + 1
        self.mainwindow.log_text_edit.append(f'1111')

in constructor add

class MainWindow(QWidget):
    def __init__(self):
        self.RequestThread_instance = RequestThread(mainwindow=self)

add handler click button:

 def connections(self):
        self.start_task_button.clicked.connect(self.start_task)

    def start_task(self):
        print('start_task')
        self.RequestThread_instance.start()
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Sergey Polykhov