title: Why does a QDialog close the whole application if it has started a thread?
body: <p>If I create an application with a MainWindow and a QDialog and then open and close the dialog the main window remains open.</p>
  <p>But if my QDialog starts a thread, and once this thread is finished I close the QDialog then my whole application closes.</p>
  <p>On the simple app below you can reproduce my problem. It's ok if I open the dialog and close without launch the tread. But if I launch the thread and close the dialog after finished the application terminate.</p>
  <p>Can you tell me where is my mistake?</p>
  <pre><code>import sys
  from PyQt5.QtWidgets import QApplication, QDialog, QMainWindow, QPushButton, QVBoxLayout
  from PyQt5.QtCore import QThread, QObject, pyqtSignal
  from time import sleep
  from PyQt5.Qt import QLabel
  
  class MainWindow(QMainWindow):
      def __init__(self):
          super().__init__()
  
          self.setWindowTitle(&quot;My App&quot;)
  
          button = QPushButton(&quot;Press me for a dialog!&quot;)
          button.clicked.connect(self.button_clicked)
          self.setCentralWidget(button)
  
      def button_clicked(self):
          my_dialog = myDialog(parent=self)
          my_dialog.exec()
  
  class myDialog(QDialog):
      def __init__(self, parent=None):
          super(myDialog, self).__init__(parent)
          self.setWindowTitle('My dialog')
          self.button = QPushButton(&quot;Run long task&quot;)
          self.button.clicked.connect(self.run_long_task)
          self.message = QLabel(&quot;Long task not launched&quot;)
          self.layout = QVBoxLayout()
          self.layout.addWidget(self.button)
          self.layout.addWidget(self.message)
          self.setLayout(self.layout)
  
      def run_long_task(self):
          self.message.setText('Long task running')
          self.thread = QThread()
          self.worker = LongTask()
          self.worker.long_task_finished.connect(self.long_task_finished)
          self.thread.started.connect(self.worker.work)
          self.worker.moveToThread(self.thread)
          self.thread.start()
  
      def long_task_finished(self):
          self.message.setText('Long task finished')
  
  class LongTask(QObject):
      long_task_finished = pyqtSignal()
  
      def work(self):
          sleep(5)
          self.long_task_finished.emit()
  
  
  app = QApplication(sys.argv)
  window = MainWindow()
  window.show()
  app.exec()
  </code></pre>
  <p>Thanks for your help.</p>