title: How to close other windows when the main window is closed in pyqt5
body: <p>I want to close all other windows opened by the main window when the main window is closed.</p>
  <p>Please find below the min. code that I was testing:</p>
  <pre><code>from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLabel, QVBoxLayout, QWidget
  
  import sys
  
  
  class AnotherWindow(QWidget):
      &quot;&quot;&quot;
      This &quot;window&quot; is a QWidget. If it has no parent, it
      will appear as a free-floating window as we want.
      &quot;&quot;&quot;
      def __init__(self):
          super().__init__()
          layout = QVBoxLayout()
          self.label = QLabel(&quot;Another Window&quot;)
          layout.addWidget(self.label)
          self.setLayout(layout)
  
  
  class MainWindow(QMainWindow):
  
      def __init__(self):
          super().__init__()
          self.button = QPushButton(&quot;Push for Window&quot;)
          self.button.clicked.connect(self.show_new_window)
          self.setCentralWidget(self.button)
  
      def show_new_window(self, checked):
          self.w = AnotherWindow()
          self.w.show()
  
      def close_another_window(self):
          if self.w:
              self.w.close()
  
  
  app = QApplication(sys.argv)
  
  w = MainWindow()
  app.aboutToQuit.connect(w.close_another_window)
  w.show()
  app.exec()
  </code></pre>
  <p>As shown above I tried using the <code>aboutToQuit</code> option of the <code>QApplication</code>, but it only gets called when the another window also is closed.</p>
  <p>I want to close the another window automaticaly when the mainwindow is closed.</p>