Skip to content Skip to sidebar Skip to footer

Pyqt5 - How To Emit Signal From Worker Tread To Call Event By Gui Thread

As I Mentioned in Title. How can i do something like this? class Main(QWidget): def __init__(self): super().__init__() def StartButtonEvent(self)

Solution 1:

Just use the QThread.finished signal here. It will be executed automatically if you finish your thread. Of course you can also define your own custom signal if you want.

from PyQt5.QtCore import pyqtSignal

class Main(QWidget):

    def __init__(self):
        super().__init__()

    def StartButtonEvent(self):
        self.test = ExecuteThread()
        self.test.start()
        self.test.finished.connect(thread_finished)
        self.test.my_signal.connect(my_event)

    def thread_finished(self):
        # gets executed if thread finished
        pass

    def my_event(self):
        # gets executed on my_signal 
        pass


class ExecuteThread(QThread):
    my_signal = pyqtSignal()

    def run(self):
        # do something here
        self.my_signal.emit()
        pass

Post a Comment for "Pyqt5 - How To Emit Signal From Worker Tread To Call Event By Gui Thread"