title: QWidget: must construct QApplication Before QWidget python error
body: <p>I am aware there is various responses to this sort of questions but I havent been able to gage what the issue is as other responses have variations in their question becuase of the code. Sorry if it seems arrogant or abnoxious.</p>
  
  <p>I have created a login window for my booking system which is not shown here as nothing to do with the issue. Now Im calling a function which creates a new window(QWidget) when login is successful but get the error QWidget: must construct QApplication before QWidget. Tried looking for answers but couldn't find any reelevant and python based answers.</p>
  
  <p>Any help would be really appreciated. Thanks in advance.</p>
  
  <pre><code>def Login_Window():
  
      app = QApplication(sys.argv)
  
      tabwidget = QTabWidget()
  
      widget  = QWidget()
      layout = QGridLayout(widget)
  
      username = QLabel(widget)
      username.setText("me")
  
      tabwidget.addTab(widget,"Adding A Booking")
      tabwidget.show()
      app.exec_()
  
  class Login_Setup(QWidget):
  
      def __init__(self):
  
          super().__init__()
          self.init_UI()
  
      def init_UI(self):   
  
          self.username        = QLabel("Username --&gt;")
          self.password        = QLabel("Password --&gt;")
  
          self.username_entry  = QLineEdit()
  
          usernames = self.usernames_read()
          autocomplete = QCompleter(usernames)
  
          self.username_entry.setCompleter(autocomplete)
          self.username_entry.setPlaceholderText("Enter username...")
  
          self.password_entry  = QLineEdit()
          self.password_entry.setPlaceholderText("Enter password...")
          self.password_entry.setEchoMode(QLineEdit.Password)
          self.login_button    = QPushButton('Login')
          self.space1          = QLabel()
          self.space2          = QLabel()
          self.progress = QProgressBar(self)
  
          self.check = QCheckBox("Show Password?",self)
          self.check.stateChanged.connect(self.password_view)
  
          y  = QVBoxLayout() # Adding veritcal layout. 
  
          x1 = QHBoxLayout()# First H layout
          x1.addWidget(self.username)
          x1.addWidget(self.username_entry)
  
  
          y.addLayout(x1)# Adding H layout
  
          x2 = QHBoxLayout()# Second H layout
          x2.addWidget(self.password)
          x2.addWidget(self.password_entry)
          x2.addWidget(self.check)
  
          y.addLayout(x2)# Adding 2nd H Layout
  
          x3 = QHBoxLayout()
          x3.addWidget(self.space1)
          x3.addWidget(self.space2)
          x3.addWidget(self.progress)
          x3.addWidget(self.login_button)
  
          y.addLayout(x3)
  
          self.login_button.clicked.connect(self.login_trigger)
          self.setLayout(y)
          self.show()
  
      def usernames_read(self):
  
          usernames = []
  
          with open('usernames.txt','r') as fo:
              for line in fo:
                  usernames.append(line.strip().replace("\n",""))
          return usernames
  
      def password_view(self,state):
          if state == QtCore.Qt.Checked:
              self.password_entry.setEchoMode(QLineEdit.Normal)
          else:
              self.password_entry.setEchoMode(QLineEdit.Password)
  
      def login_trigger(self):
  
          self.completed = 0
  
          while self.completed&lt;100:
              self.completed+=0.001
              self.progress.setValue(self.completed)
  
          username = self.username_entry.text()
          password = self.password_entry.text()
  
          self.username_entry.clear()
          self.password_entry.clear()
  
          verify, hashed = Security.check_login(username,password)
  
          if  (verify == True) and (Security.check_admin(hashed) == True):
              Login_Page.hide()
              **Load_Window()**
  
          elif (verify == True):
              Login_Page.hide()
              **Load_Window()**
  
          else:
              self.progress.setValue(0)
              decision = QMessageBox.warning(self,"Invalid Attempt", "Invalid username and/or password!",QMessageBox.Ok | QMessageBox.Help)
              if decision == QMessageBox.Help: 
                  QMessageBox.information(self,"Invalid Attempt", "The username or/and password you entered where not found on the database or hasn't been approved by the admin!",QMessageBox.Ok)
              else:
                  pass         
  
  class Login(QMainWindow):
  
      def __init__(self):
  
          super().__init__()
  
          self.GUI = Login_Setup()
          print("set")
          self.setCentralWidget(self.GUI)
  
          self.setWindowIcon(QtGui.QIcon('mot.png'))
  
          self.init_UI()
  
      def init_UI(self):
          "----Making the main menu bars and editing--------"
          bar = self.menuBar()
  
          file = bar.addMenu('File')
  
          exit_action = QAction(QIcon('exit.png'),'Exit',self)
          exit_action.setShortcut('Ctrl+Q')
          exit_action.triggered.connect(self.quit_trigger)
  
          file.addAction(exit_action)
          "------------------------------------------------"
  
          self.setWindowTitle('MOT LOGIN')
          self.show()
  
  
      def quit_trigger(self):
          """
          quit_trigger() function desciption!
  
              Inputs: none
  
              Outputs: none
  
              Description: none
  
          """
  
          choice = QMessageBox.question(self,'Exit Prorgam',"Are you sure you want to quit?",QMessageBox.Yes|QMessageBox.No)
  
          if choice == QMessageBox.Yes: 
              sys.exit()
  
          else:
              pass
  
  class Options_Setup(QWidget):
  
      def __init__(self):
  
          super().__init__()
  
          self.make_booking = QPushButton()
          self.remove_booking = QPushButton()
          self.edit_booking = QPushButton()
          self.search_booking = QPushButton()
          self.add_users = QPushButton()
  
          self.make_booking.setText("Make Booking!")
          self.remove_booking.setText("Remove Booking!")
          self.edit_booking.setText("Edit Booking!")
          self.search_booking.setText("Search For Booking!")
          self.add_users.setText("Add Repeat Customer")
  
          self.init_UI()
  
      def init_UI(self):
  
          y = QVBoxLayout()
  
          self.make_booking.clicked.connect(self.make_appointment)
          self.remove_booking.clicked.connect(self.remove_appointment)
          self.search_booking.clicked.connect(self.find_booking)
          self.add_users.clicked.connect(self.add_repeat)
  
          x1 = QHBoxLayout()
          x1.addWidget(self.make_booking)
          x1.addWidget(self.remove_booking)
  
          y.addLayout(x1)
  
          x2 = QHBoxLayout()
          x2.addWidget(self.edit_booking)
          x2.addWidget(self.search_booking)
  
          y.addLayout(x2)
  
          x3 = QHBoxLayout()
          x3.addWidget(self.add_users)
  
          y.addLayout(x3)
  
          self.setLayout(y)
          self.show()
  
      def find_booking(self):
          Options_Page.hide()
          Finding_Booking.show()
  
      def make_appointment(self):
  
          Options_Page.hide()
          Making_Booking.show()
  
      def remove_appointment(self):
  
          Options_Page.hide()
          Removing_Booking.show()
  
      def add_repeat(self):
          Options_Page.hide()
          Add_User.show()
  
  class Options(QMainWindow):
  
      def __init__(self):
  
          super().__init__()
  
          self.GUI = Options_Setup()
          self.setCentralWidget(self.GUI)
  
          self.setWindowIcon(QtGui.QIcon('mot.png'))
          self.setWindowTitle("Options Page")
  
          self.init_UI()
  
      def init_UI(self):
  
          "----Making the main menu bars and editing--------"
          bar = self.menuBar()
  
          file = bar.addMenu('File')
  
          exit_action = QAction(QIcon('exit.png'),'Exit',self)
          exit_action.setShortcut('Ctrl+Q')
          exit_action.triggered.connect(self.quit_trigger)
  
          file.addAction(exit_action)
          "------------------------------------------------"
          self.show()
  
  
      def quit_trigger(self):
  
          choice = QMessageBox.question(self,'Exit Prorgam',"Are you sure you want to quit?",QMessageBox.Yes|QMessageBox.No)
  
          if choice == QMessageBox.Yes: 
              sys.exit()
  
          else:
              pass
  
  Login_Page = Login()
  </code></pre>