This short snippets allows you to restart your application.
The first step is to close the application:
qApp->exit(EXIT_CODE_RESTART);
The EXIT_CODE_RESTART
is just a constant we use to query that the application needs to be restarted instead of just terminated.
In your main.cpp
you need to query the return code from app.exec()
:
#include <QProcess>
ret = app.exec();
if (ret == EXIT_CODE_RESTART)
{
//restart application
QProcess::startDetached(qApp->arguments()[0], qApp->arguments());
}
The application ends and is restarted.