jeudi 5 mars 2015

why signal emit failed in pyside?


Vote count:

0




This is my code:



from PySide import QtCore, QtGui
import sys
import time

class TestThread(QtCore.QThread):

def __init__(self):
self.finished_flag = False
super(TestThread, self).__init__()

def finished(self):
print('==========finished function is invoked!=======================')
self.finished_flag = True

def run(self):
while(True):
print('thread is running...')
time.sleep(1)
if self.finished_flag:
print('thread exist!')
break


class TestDialog(QtGui.QDialog):
ForceTermimateSignal = QtCore.Signal()

def done(self, code):
print('================dialog done!==================')
self.ForceTermimateSignal.emit()
super(TestDialog, self).done(code)


if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)

dlg = TestDialog()
testThread = TestThread()

dlg.ForceTermimateSignal.connect(testThread.finished)

testThread.start()

dlg.exec_()

if testThread.isFinished():
print('thread finished')
else:
print('thread is still running!')
testThread.wait()


This is the result when run the above code and then close the dialog:



thread is running...
thread is running...
thread is running...
thread is running...
================dialog done!==================
thread is still running!
thread is running...
thread is running...
thread is running...


so I want to know: why emitting ForceTermimateSignal of dlg can not invoke 'finished' function of object testThread?



asked 36 secs ago







why signal emit failed in pyside?

Aucun commentaire:

Enregistrer un commentaire