QT实现软件重启

//重启软件 void MainWindow::on_pushButton_UI_reboot_clicked()

{ //方式1 需要主函数中事件循环判断 //qApp->exit(773); //重启代码,773 = 'r'+'e'+'s'+'t'+'a'+'r'+'t' ==>restart

//方式2 直接重启 #ifdef Q_OS_WIN qApp->closeAllWindows();

QProcess::startDetached(qApp->applicationFilePath(), QStringList()); exit(0);

#elif defined (Q_OS_LINUX) qApp->closeAllWindows();

QProcess::startDetached(qApp->applicationFilePath(), QStringList("-qws"));

QProcess::execute("-qws"); //经测试linux下需要这样,软件才能运行 #endif }

原文地址:https://www.cnblogs.com/luxiaolai/p/4299531.html