我想你可能弄错了。你需要在一个单独的线程中完成工作,这样它就不会冻结应用程序。但您也希望能够更新进度条。您可以通过使用QThread创建工作类来实现这一点。qthread能够发出信号,用户界面可以监听这些信号并采取适当的操作。
首先,让我们创建你的工人阶级。#Inherit from QThread
class Worker(QtCore.QThread):
#This is the signal that will be emitted during the processing.
#By including int as an argument, it lets the signal know to expect
#an integer argument when emitting.
updateProgress = QtCore.Signal(int)
#You can do any extra things in this init you need, but for this example
#nothing else needs to be done expect call the super's init
def __init__(self):
QtCore.QThread.__init__(self)
#A QThread is run by calling it's start() function, which calls this run()
#function in it's own "thread".
def run(self):
#Notice this is the same thing you were doing in your progress() function
for i in range(1, 101