贵有恒,何必三更起、五更眠、最无益,只怕一日曝、十日寒。这篇文章主要讲述How to Restart Qt Application相关的知识,希望能为你提供帮助。
How to restart QtApplication
As we know, Restarting Application means to exit current application, then to call another application. So, let‘s see how exit of one application.
Qt Application
int main(int argc, char** argv)
{
QApplication app(argc, argv);
Widget w;
w.show()
return app.exec();
}
The code snippet,last line
return app.exec()
let Qt application in main event loop. if you want to exit main event loop, Just callQCoreApplication::exit(int);
or QCoreApplication::quit();
QApplication
has one property called quitOnLastWindowClosed
, it means the application will exit after last window closed.About how to close all windows, we can use
QApplication::closeAllWindows()
, It is better way for using quit
to exit application. That way, We can let all windows object revice close event, and do some thing before destroy.Call another ApplicationIn Qt, It is better let
QProcess
to do this. It let another application to run and not has father-son relationship.QProcess::startDetached(qApp->
applicationFilePath(), QStringList());
if applicationFilePath not continues space char, we can use
QProcess::startDetached(qApp->
applicationFilePath());
Example one
qApp->
quit();
QProcess::startDetached(qApp->
applicationFilePath(), QStringList());
【How to Restart Qt Application】or
qApp->
closeAllWindow();
QProcess::startDetached(qApp->
applicationFilePath(), QStringList());
Example two
/**773 = '
r'
+'
e'
+'
s'
+'
t'
+'
a'
+'
r'
+'
t'
*/
qApp->
exit(773);
int main(int argc, char** argv)
{
int ret = app.exec();
if (ret == 773) {
QProcess::startDetached(qApp->
applicationFilePath(), QStringList());
return 0;
}
return ret;
}
推荐阅读
- android解决AVD中文路径无法启动问题
- Android画图系列——自己定义View绘制基本图形
- android入门问题--R文件丢失
- Android View移动的六种方法
- MQ报错java.lang.IllegalStateException: Failed to load ApplicationContext
- mybatis 模糊查询 mapper.xml的写法(转)
- Android Studio NDK 新手教程--Java对象的传递与改动
- NGINX TCP和UDP负载均衡
- Burp Suite抓包App