How do I write the Pyside2 QThread parameter?

Asked 2 years ago, Updated 2 years ago, 138 views

class _Date_Thread(QThread):
    def run (self, param): # Where the parameter should be entered
        while True:
            print(param)
            time.sleep(0.1)


 class Ui_MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.th = _Date_Thread()
        self.th.start()

I know that QThread is executed in this way, but how do I specify the parameters of the function to be executed in QThread?

pyside2 python pyqt thread qthread

2022-09-20 11:07

1 Answers

class _Date_Thread(QThread):
    def __init__(self, param):
        self.param = param
    def run(self): # Where the parameter should enter
        while True:
            print(self.param)
            time.sleep(0.1)


 class Ui_MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.th = _Date_Thread(param)
        self.th.start()

I can do it like this.


2022-09-20 11:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.