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

版权声明:引用请注明出处 https://blog.csdn.net/quange_style/article/details/71258171

在嵌入式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;
}

猜你喜欢

转载自blog.csdn.net/quange_style/article/details/71258171
今日推荐