我正在使用PyQt构建应用程序GUI,并且有一个功能需要在后台运行,因此我正在使用QThread(请参见下面的代码)。 我收到“进程结束,退出代码为-1073740791(0xC0000409)”
该问题如何解决? 谢谢
import time
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
from PyQt5.QtCore import pyqtSignal, QThread
import sys
class MyApp(QWidget):
def __init__(self):
super(QWidget, self).__init__()
btn = QPushButton('Run')
layout = QVBoxLayout()
layout.addWidget(btn)
btn.clicked.connect(self.my_function)
self.setLayout(layout)
def my_function(self):
my_task = Task()
my_task.done_signal.connect(self.done)
my_task.start()
def done(self):
print('done')
class Task(QThread):
done_signal = pyqtSignal()
def run(self):
# Do some work here
time.sleep(3)
self.done_signal.emit()
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MyApp()
w.show()
sys.exit(app.exec_())