how to restart an application in qt?
c++, qdialog, qt, restart
Solution
You can use `QProcess::startDetached` to run an instance of your application in a new process and detach from it. After that you should exit the application :
QProcess process;
process.startDetached("myApp",QStringList());
qApp->quit();
Here `myApp` is the name of the executable file of the application. On Windows it can be `myApp.exe`.
Problem
I do this works for restarting my game but program has error .I want to show a `QDialog` when user losses .In this `QDilag` i put two `pushbutton` for retry and exit.also i have a `QDialog` for beginning of game.Where is my mistake? (I read similar questions and do according these but yet i have problem) ``` extern int const EXIT_CODE_REBOOT; mydialog_end::mydialog_end(QWidget *parent) : QDialog(parent { retry=new QPushButton(this); exit=new QPushButton(this); retry->setText("RETRY"); exit->setText("EXIT"); connect(retry,SIGNAL(clicked()),this,SLOT(on_retry_clicked())); connect(exit,SIGNAL(clicked()),this,SLOT(on_exit_clicked())); } void mydialog_end::on_retry_clicked() { qApp->exit(EXIT_CODE_REBOOT); accept(); } void mydialog_end::on_exit_clicked() { //what do i do for end of game? reject(); } //////////////in class myenemy/////// public slots: void loss(); void Myenemy1::loss() { if(this->collidesWithItem(_mario)) { //do something.... mydialog_end dialog; dialog.exec(); } } //////////////in main//////////// extern int const RESTART_CODE; int main(int argc, char *argv[]) { Mydialogstart dlg;//a dialog for beginning game int state= dlg.exec(); int return_from_event_loop_code=0; do { QApplication a(argc, argv); MainWindow w; if( state==QDialog::Accepted) { w.show(); qDebug()<<"accepted"; } else if(state==QDialog::Rejected) { qDebug()<<"rejected"; dlg.close(); return 0; } return_from_event_loop_code = a.exec(); } while(return_from_event_loop_code==RESTART_CODE); return return_from_event_loop_code; } ```