I'm a PyQt5 newbie. I've written the following code which should ideally terminate.
from PyQt5.QtCore import QCoreApplication, pyqtSignal, QObject
import sys
import thread
class MainWindow(QObject):
def __init__(self):
super().__init__()
self.myMethod()
def myMethod(self):
self.myThread = thread.MainWindow(self)
self.myThread.threadTerminate.connect(self.finished)
self.myThread.start()
def finished(self, arg1):
print("Message recieved is "+arg1)
QCoreApplication.quit()
if __name__ == '__main__':
qApp = QCoreApplication(sys.argv)
w = MainWindow()
qApp.exec_()
The thread code is:
from PyQt5.QtCore import QThread, QCoreApplication, pyqtSignal
import sys
import time
class MainWindow(QThread):
threadTerminate = pyqtSignal(bool)
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.itsOver = False
def run(self):
print("Hello World!")
time.sleep(3)
print("Alice")
time.sleep(4)
print("Bob")
time.sleep(4)
self.stop()
def stop(self):
print("About to terminate....")
self.itsOver = True
self.threadTerminate.emit(self.itsOver)
self.terminate()
What am I doing wrong? Is there any way to trace the execution flow of my program and know the state of my variables?