pyqt thread学习

发布时间 2023-09-25 17:18:51作者: 西北逍遥

 

from PyQt5.QtCore import QThread, pyqtSignal
import time

class MyThread(QThread):
    finished = pyqtSignal()

    def run(self):
        print('Thread started.')
        time.sleep(5)  # 模拟一个耗时任务
        print('Thread finished.')

app = QApplication([])

thread = MyThread()
thread.start()

# 在任何你需要停止线程的时候
thread.wait()

print('Thread stopped.')

 

 

#############################