This question already has an answer here:
- how to restart my own qt application? 8 answers
1.) I would like to restart my QT4 application. Just a normal shutdown and start of the same application.
2.) Why? Well i need an Option to "reset" everything. To restart the application seems to be the easiest way to do this. The problem is, that there are a LOT of classes and everything. I dont have the time to put every setting of them back to standard, every textBox, Widget to clear... I Know application restart is not the best way, what do you think is there another way?
Thank You
1) You can run a Script, Schedule the OS to start your app later.
2) Write a separate class which contains all your application Settings. Reset whenever required.
For restarting an application you can use
startDetached
after quiting the process:you could delete the classes and create new ones in main() under the same QApplication
Funny request. Just reserve an exit code for "restart" and do something like (untested):
Then you can just call QApplication::exit(EXIT_RESTART) anywhere and you should be good to go. Or use a wrapper script to do the same. (Make sure in both cases that you handle command line arguments satisfactorily if you app takes any.)
A cleaner approach would be to connect all the things that need to be reset to the same signal.
The sane thing to do in such a case is to put all the stuff that creates/initializes widgets, etc., in a single function (of course, it can call sub-functions). When you need to reset everything, simply call it. Depending on the exact implementation, you may need to delete/un-initialize the stuff first.
This method works on PyQt. I wrote it for erasing all settings and to restart the application with clean settings.
application_main
is the main method, andclearSettings
is the slot that clears the settings.