第三章:嵌入式QT--自重启

xiaoxiao2021-02-28  43

在嵌入式QT 里面,有时候需要自重启QT进程,这时候就需要用到startDetached()函数。 该函数的主要作用是:Starts the program program with the arguments arguments in a new process, and detaches from it。

实现完美的自重启需要以下步骤: 1、触发

#define QtQuitFlag 90 void messageSlot(){ qApp->closeAllWindows();//Closes all top-level windows qApp->exit(QtQuitFlag);//Tells the application to exit with a return code }

2、进程处理

//*******main.cpp*******// #define QtQuitFlag 90 void main() { QApplication a(argc, argv); int ret_val; ret_val=a.exec(); if (ret_val == QtQuitFlag) { ....//注销相关 QStringList args; args.append("-qws"); QProcess::startDetached(qApp->applicationFilePath(), args); return ret_val; } return ret_val; }
转载请注明原文地址: https://www.6miu.com/read-51505.html

最新回复(0)