Scenario One: Restart via process
void mainwindow::on_pushbutton_clicked ()
{
//qapp->quit ();
Qapp->closeallwindows (); Closing multiple windows is better than calling quit because the window can accept the Close event
//If it is on an embedded arm board, you need to add-qws parameter
//qstringlist args;
Args.append ("-qws"); parameter information
//args.append ("&"); Background Run
//qprocess::startdetached (Qapp->applicationfilepath ());//The Path of the program is not a space or Chinese can also be used
Qprocess::startdetached (Qapp->applicationfilepath (), qstringlist ());
}
Note: because Qapp, need to include header file # include <QApplication> scenario two: Restart via event loop
void mainwindow::on_pushbutton_2_clicked ()
{
// 773 = ' R ' + ' E ' + ' s ' + ' t ' + ' a ' + ' r ' + ' t '
/ = = >restart
//#define Exit_restart 773
qapp->exit (773);
}
int main (int argc, char *argv[])
{
qapplication A (argc, argv);
int ret =-1;
Do
{
MainWindow w;
W.show ();
ret = A.exec ();
} while (ret! = 0);
return ret;
}
Note: GIF frame count reason, event cycle restart too fast, recording effect is not obvious, has actually restarted