well that because your app has not time to update the gui so you need to use
time.sleep function
and QtGui.Application.processEvents function....
the time.sleep function takes one arg is an int defined how many seconds the python script will pause...
and the QtGui.Application.processEvents function is a Qt function that let the app to process the GUI events....
example :
the freezing script:
import itertools ,string
x=1
file=open("file","w")
while x<=200:
it=itertools.product(string.printable,repeat=x)
for i in it:
ij="".join(i)
file.write("ij"+"\n")
x=x+1
file.close()here probably the GUI will freeze because it is a long loop inside another loop...
so here what we can do:
import itertools ,string,time,QtGui
gui=QtGui.Application.processEvents
x=1
file=open("file","w")
gui()
while x<=200:
it=itertools.product(string.printable,repeat=x)
time.sleep(0.1)
gui()
for i in it:
ij="".join(i)
time.sleep(0.001)
gui()
file.write("ij"+"\n")
gui()
x=x+1
gui()
file.close()
and now it won't freeze at all :)gui()
Thanks for the usefull trick, using gui=QtGui.Application.processEvents !
ReplyDeleteso what header did u use ??
ReplyDeletethis is PyQt4 module for python not a header file for C++
Deletefor C++ use QApplication::processEvents()