python - PyQt Progressbar QThread does not work correct -


i have problem code. plan show progress of loop using progressbar. idea use qthread. code below works somehow, not 100 percently correct. progressbar shows progress of loop, not via thread i.e. if try click more once on stop gui freezes. not qtcore expert. can please me , tell me why not work way want work?

thanks lot!

from pyqt4 import qtgui, qtcore  #progressbar class mycustomwidget(qtgui.qwidget):      def __init__(self, parent=none):         super(mycustomwidget, self).__init__(parent)         layout = qtgui.qvboxlayout(self)                 self.progressbar = qtgui.qprogressbar(self)         self.progressbar.setrange(0,100)         layout.addwidget(self.progressbar)      #update progressbar     def onprogress(self, i):         self.progressbar.setvalue(i)         if self.progressbar.value() >= self.progressbar.maximum():             self.close()  #threading class class asa(qtcore.qthread):     notifyprogress = qtcore.pyqtsignal(int)     def run(self, i):          #sends new information update function         self.notifyprogress.emit(i)         time.sleep(0.01)  #-----------------------------------------# #main function app = qtgui.qapplication(sys.argv) bar = mycustomwidget() bar.show()  bar.asa = asa() bar.asa.notifyprogress.connect(bar.onprogress) bar.asa.start()  #for loop progressbar in range(105):     asa.run(bar.asa, i)     time.sleep(0.5)    sys.exit(app.exec_()) 

the loop needs run inside thread itself:

def run(self):     #sends new information update function     in range(105):         self.notifyprogress.emit(i)         time.sleep(0.01) 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -