Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. PyQt5 application not restarting itself
Forum Updated to NodeBB v4.3 + New Features

PyQt5 application not restarting itself

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fuchsiaff
    wrote on last edited by
    #1

    So I followed this documentation
    https://wiki.qt.io/How_to_make_an_Application_restartable

    I need to make my software restart after doing some updates but it exists successfully but then doesn't start up anymore.

    My code looks like this:

        def restart(self):
    
            qApp.exit(-123456789)
    

    Note: The function is inside the Main class which inherits from QMainWindow

    1 Reply Last reply
    0
    • Kent-DorfmanK Offline
      Kent-DorfmanK Offline
      Kent-Dorfman
      wrote on last edited by
      #2

      did you really follow that documentation? There is nothing magical about the exit code. you have to check it as a loop condition in main. I don't see enough of your code to know whether you did that.

      1 Reply Last reply
      1
      • F Offline
        F Offline
        Fuchsiaff
        wrote on last edited by
        #3

        Since python does not have a do while loop, here's something I tried

        if __name__ == '__main__':
            app = QApplication(sys.argv)
            current_exit_code = 0
            while True:
                ex = Main()
                ex.setFont(QFont("Consolas", 10))
                ex.setStyleSheet(blue)
                #welcome = Welcome(ex)
                ex.showMaximized()
                current_exit_code = app.exec()
                if current_exit_code == -123456789:
                    break
        

        That didn't work either

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Fuchsiaff
          wrote on last edited by
          #4

          Here's what I did to make it work:

           def restart(self):
          
                  os.execl(sys.executable, sys.executable, *sys.argv)
          

          That simple function will restart the whole script

          JonBJ 1 Reply Last reply
          0
          • Kent-DorfmanK Offline
            Kent-DorfmanK Offline
            Kent-Dorfman
            wrote on last edited by
            #5

            reread the documentation you referenced above. You should instantiate QApplication inside your while loop, not outside.

            1 Reply Last reply
            1
            • F Fuchsiaff

              Here's what I did to make it work:

               def restart(self):
              
                      os.execl(sys.executable, sys.executable, *sys.argv)
              

              That simple function will restart the whole script

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Fuchsiaff
              That's fine, but it's a totally different kind of application "restart" versus what the code in the link is doing :)

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved