I have an odd problem with QThreads in (pyqt). I tested QThread with implementing run method and running an infinite loop inside it. it does not affect main thread (gui). but when I emit a signal like below pseudo code any long running loop or i/o affect on main thread and makes gui freeze.
class MyThread(QThread):
def __init__(self , *args):
QThread.__init__(self , *args)
self.connect(self , SIGNAL("do_some_io(QString)") , self.doSomething)
def doSomething(self , params):
#do some large i/o and loops
parent.emit( SIGNAL("process_done()") )
class MyDialog(QDialog):
def __init__(self , *args):
QThread.__init__(self , *args)
self.Thread = MyThread(self)
self.Thread.start()
self.connect(self.btn , SIGNAL("clicked()") , self.buttonClicked)
self.connect(self , SIGNAL("process_done()") , self.showMsgBox)
def buttonClicked(self):
self.Thread.emit( SIGNAL("do_some_io(QString)") , "param" )
def showMsgBox(self):
#show messagebox