title: Get application quit signal before windows are closed in QT
body: <p>I have a Qt Application with multiple main windows and want to get a signal when the App is about to quit while all windows are still up.</p>
  
  <p>The <code>QApplication.aboutToQuit</code> signal doesn't work for me because it only fires after all windows have been closed.</p>
  
  <p>All other answers I've seen suggest implementing the main window's <code>closeEvent()</code> function, but I have multiple main windows and I couldn't find any way to differentiate <code>CloseEvent</code>s between a normal <code>closeEvent</code> of just a single window being closed and a close event from when the whole application is closing after <code>QMD+Q</code> or the using clicking quit in the task bar or for whatever reason it quits.</p>
  
  <p>How do I get a signal for that only when the whole application is about to quit but before any windows are closed?</p>
  
  <p>What happens when I press Cmd+Q or right click quit the task bar icon:</p>
  
  <ol>
  <li>(I want a signal at this point) &lt;-</li>
  <li>all windows get a closeEvent() </li>
  <li>aboutToQuit() fires </li>
  <li>app quits</li>
  </ol>
  
  <p>What I want is to get a signal before any of that happens and all the windows are still open.</p>
  
  <p>Edit: minimal example</p>
  
  <pre><code>from PyQt5.QtGui import QCloseEvent
  from PyQt5.QtWidgets import QApplication, QWidget
  
  class Win(QWidget):
      def closeEvent(self, event: QCloseEvent):
          # implementing a custom closeEvent doesn't help me
          # this is called for every normal manual window close and when the application quits
          # I only want to run something when the full application gets shut down, not just this window
          # can't see any way to differentiate between the two
          print("closeEvent", event.type(), event)
          return super().closeEvent(event)
  
  
  if __name__ == '__main__':
      app = QApplication([])
      app.aboutToQuit.connect(lambda :print("about to quit, this is too late, by now all windows are closed"))
  
      #What I need
      # app.beforeQuitSignal.connect(lambda :print("signal that it's gonna quit, before any of the windows are closed"))
  
      #stuff I've tried that didn't work either
      app.quit = lambda *args:print("quit, doesnt get called")
      app.exit = lambda *args:print("exit, doesnt get called")
      app.closeAllWindows = lambda *args:print("closeAllWindows, doesnt get called")
  
      mainwins = []
      for i in range(5):
          win = Win()
          win.setGeometry(100*i,100*i, 400,400), win.show(), win.raise_()
          mainwins.append(win)
  
      app.exec_()
  </code></pre>