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. Self restarting application on crash

Self restarting application on crash

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 2.1k 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.
  • mandruk1331M Offline
    mandruk1331M Offline
    mandruk1331
    wrote on last edited by
    #1

    I want my application to self restart if it crashes. I have a couple of ideas of how to do this, but maybe you could recommend me a better one. Idea #1: Create a console application (hide it), which will start my GUI application, and if my GUI crashes it will create a new GUI application. Idea #2 By using try, catch, throw therefore if I will get an unknown error which I won't be able to handle it will create a new instance of the GUI application and will close the current one (the one that crashed). Is this are good ideas or maybe you can recommend me smth better?

    Mandruk1331

    kshegunovK 1 Reply Last reply
    0
    • Chris HennesC Offline
      Chris HennesC Offline
      Chris Hennes
      wrote on last edited by
      #2

      To be honest, your best bet is to make sure your application doesn't crash! It's too easy to get into an infinite loop where your app crashes over and over and gets restarted over and over, and your users aren't going to like that. Are you having problems with your app crashing? Maybe we can help you resolve those instead.

      Chris Hennes, Pioneer Library System

      mandruk1331M 1 Reply Last reply
      2
      • Chris HennesC Chris Hennes

        To be honest, your best bet is to make sure your application doesn't crash! It's too easy to get into an infinite loop where your app crashes over and over and gets restarted over and over, and your users aren't going to like that. Are you having problems with your app crashing? Maybe we can help you resolve those instead.

        mandruk1331M Offline
        mandruk1331M Offline
        mandruk1331
        wrote on last edited by mandruk1331
        #3

        @Chris-Hennes Nope no problems with the crashes, but sometimes the app can crash. My app is going to launch other applications and I don't know if the app will crash or not, therefore I want to restart the app if it crashes. I will make smth like a counter so if it will self restart more that say 3 times it will stop doing that.

        Mandruk1331

        1 Reply Last reply
        0
        • Chris HennesC Offline
          Chris HennesC Offline
          Chris Hennes
          wrote on last edited by
          #4

          How are you launching the apps you are worried about crashing? Are you using QProcess?

          Chris Hennes, Pioneer Library System

          mandruk1331M 1 Reply Last reply
          0
          • Chris HennesC Chris Hennes

            How are you launching the apps you are worried about crashing? Are you using QProcess?

            mandruk1331M Offline
            mandruk1331M Offline
            mandruk1331
            wrote on last edited by
            #5

            @Chris-Hennes That's what I was planning to use

            Mandruk1331

            1 Reply Last reply
            0
            • Chris HennesC Offline
              Chris HennesC Offline
              Chris Hennes
              wrote on last edited by
              #6

              Then you can connect to the finished signal and get the return code of the program, which will (generally) tell you if the program crashed.

              Chris Hennes, Pioneer Library System

              1 Reply Last reply
              1
              • mandruk1331M mandruk1331

                I want my application to self restart if it crashes. I have a couple of ideas of how to do this, but maybe you could recommend me a better one. Idea #1: Create a console application (hide it), which will start my GUI application, and if my GUI crashes it will create a new GUI application. Idea #2 By using try, catch, throw therefore if I will get an unknown error which I won't be able to handle it will create a new instance of the GUI application and will close the current one (the one that crashed). Is this are good ideas or maybe you can recommend me smth better?

                kshegunovK Offline
                kshegunovK Offline
                kshegunov
                Moderators
                wrote on last edited by
                #7

                @mandruk1331 said in Self restarting application on crash:

                I want my application to self restart if it crashes

                Eh, as mr Hennes said it's best to ensure your application doesn't crash to begin with. Or if it does to track down the actual bug.

                Idea #1: Create a console application (hide it), which will start my GUI application, and if my GUI crashes it will create a new GUI application.

                It's not always easy to "hide it" as it will have a console terminal attached to it. You can in principle use a daemon/service for this, but ... well I'm very suspicious of such behaviour in applications.

                #2 By using try, catch, throw therefore if I will get an unknown error which I won't be able to handle it will create a new instance of the GUI application and will close the current one

                Assuming that your "crashes" are caused by an uncaught exception (thus the runtime terminating the app due to the default OS's exception handler) it could work. But then not all errors are exceptions. If you overrun memory this is no exception, if you divide by zero it's no exception, etc.

                You could attach a SIGTERM/SIGSGV handler in principle, but again I'd be very wary of code that restarts itself while responding to those signals.

                Read and abide by the Qt Code of Conduct

                1 Reply Last reply
                2

                • Login

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