i just asking myself how to restart my own qt application?
Can somebody please show me an example?
Qt uses a command line tool that parses these project files in order to generate "makefiles", files that are used by compilers to build an application. This tool is called qmake. But, we shouldn't bother too much about qmake, since Qt Creator will do the job for us. TEMPLATE describes the type to build.
To restart application, try:
#include <QApplication> #include <QProcess> ... // restart: qApp->quit(); QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
I'm taking the other answers solutions, but better. No need for pointers, but there is a need for a ;
after the while
statement of a do { ... } while( ... );
construct.
int main(int argc, char *argv[]) { const int RESTART_CODE = 1000; do { QApplication app(argc, argv); MainWindow main_window(app); } while( app.exec() == RESTART_CODE); return return_from_event_loop_code; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With