title: How to destroy a QApplication and then run a new one without exiting the python script?
body: <p>I want to create a QApplication which is then exited using a keyboard shortcut. Then the python script should call another QApplication.</p>
  
  <p>My issues currently is that I get this error when the second QApplication is about to run:</p>
  
  <pre><code>app2 = QApplication()
  RuntimeError: Please destroy the QApplication singleton before creating a new QApplication instance.
  </code></pre>
  
  <p>I have the following structure:</p>
  
  <pre><code>| main.py
  | Q1.py
  | Q2.py
  </code></pre>
  
  <p>This is main.py:</p>
  
  <pre><code>import Q1 as record
  import Q2 as display
  
  def main():
      record.main()
      display.main()
  
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>This is Q1 which creates the problem: </p>
  
  <pre><code>import sys
  from PySide2 import QtWidgets as qtw
  from PySide2 import QtGui as qtg
  from PySide2 import QtCore as qtc
  from PySide2 import QtMultimedia as qtmm
  
  
  class MainWindow(qtw.QMainWindow):
      def __init__(self):
          super().__init__()
  
          #Create Window layout with a sound widget
          soundboard = qtw.QWidget()
          soundboard.setLayout(qtw.QGridLayout())
          self.setCentralWidget(soundboard)
          sw = SoundWidget()
          soundboard.layout().addWidget(sw)
  
          #Window Dimensions
          self.setSizePolicy(qtw.QSizePolicy.Expanding, qtw.QSizePolicy.MinimumExpanding)
  
          # Code ends here
          self.show()
  
  
  class SendOrderButton(qtw.QPushButton):
      button_stylesheet = 'background-color: blue; color: white;'
  
      def __init__(self):
          super().__init__('Send Order')
          self.setSizePolicy(qtw.QSizePolicy.Expanding, qtw.QSizePolicy.Expanding)
          self.setStyleSheet(self.button_stylesheet)
          #self.clicked.connect(qtc.QCoreApplication.instance().quit)
  
      def press_button(self):
          if self.isEnabled():
              self.setEnabled(False)
              self.setText('Send Order')
          else:
              self.setEnabled(True)
              self.setText('Sent')
  
  class SoundWidget(qtw.QWidget):
      def __init__(self):
          super().__init__()
          self.setLayout(qtw.QGridLayout())
  
          #Send Order Button
          self.sendorder_button = SendOrderButton()
          self.sendorder_button.setShortcut(qtg.QKeySequence('Tab'))
          self.layout().addWidget(self.sendorder_button, 5, 0, 1, 2)
          self.sendorder_button.clicked.connect(qtc.QCoreApplication.instance().quit)
  
  def main():
      app = qtw.QApplication(sys.argv)
      window = MainWindow()
      window.show()
      app.exec_()
  
  if __name__ == '__main__':
      app = qtw.QApplication(sys.argv)
      window = MainWindow()
      window.show()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>This is Q2.py which has the second QApplication:</p>
  
  <pre><code>import sys
  from PySide2.QtCore import (QAbstractTableModel, Slot)
  from PySide2.QtWidgets import (QAction, QApplication, QMainWindow,QWidget)
  
  class MainWindow(QMainWindow):
      def __init__(self, widget):
          QMainWindow.__init__(self)
  
          # Exit QAction
          exit_action = QAction("Exit", self)
          exit_action.setShortcut("Ctrl+Q")
          exit_action.triggered.connect(self.exit_app)
  
      @Slot()
      def exit_app(self, checked):
          sys.exit()
  
  class CustomTableModel(QAbstractTableModel):
      def __init__(self, data=None):
          QAbstractTableModel.__init__(self)
  
  class Widget(QWidget):
      def __init__(self):
          QWidget.__init__(self)
  
          # Getting the Model
          self.model = CustomTableModel()
  
  def main():
      app2 = QApplication()
      widget = Widget()
      window2 = MainWindow(widget)
      window2.show()
      sys.exit(app2.exec_())
  
  if __name__ == "__main__":
      app = QApplication()
      widget = Widget()
      window = MainWindow(widget)
      window.show()
      sys.exit(app.exec_())
  </code></pre>