pyqt如何用多线程解决卡顿问题
from PyQt5.QtWidgets import *
from function import bigFunction
from multiprocessing import Process
'''
pyqt如何用多线程解决卡顿问题
我尝试运行如下代码,但是 bigFunction 未能成功运行
需要使用多进程解决
一个很初级的问题,我该如何更改
'''
def do():
p = Process(target=bigFunction)
# bigFunction 是一个耗时且会导致程序未响应的方法
p.start()
class setElement(QWidget):
def func(self):
print('click')
def __init__(self):
super(QWidget, self).__init__()
self.setStyleSheet('')
self.button = QPushButton(self)
self.button.setText('click')
self.button.setGeometry(100,50,100,30)
self.button.clicked.connect(self.func)
self.button2 = QPushButton(self)
self.button2.setText('someText')
self.button2.setGeometry(100,230,100,30)
self.button2.clicked.connect(do)
self.show()
APP = QApplication([])
e =setElement()
APP.exec_()