qt实现重新登录 -电脑资料
【www.unjs.com - 电脑资料】
1.需求
需要实现程序操作过程中的重新启动,即经常说的重新登录功能
2.解决
在main函数中检测exec的返回值决定是关闭还是重启,使用注册函数atexit(relogin)来实现这个功能
3.代码
main.cpp
<code class="hljs" vala="">#include myrelogin.h#include<qtwidgets qapplication="">#include<qprocess>QString gstrFilePath = ;void relogin(void);int main(int argc, char *argv[]){ QApplication a(argc, argv); gstrFilePath = QCoreApplication::applicationFilePath(); myrelogin w; w.show(); int nret = a.exec(); if (nret == 2) { atexit(relogin); } return nret;}//这里启用重新启动一个新的示例void relogin(){ QProcess process; process.startDetached(gstrFilePath);}</qprocess></qtwidgets></code>
函数调用
<code class="hljs" cpp="">#include<qtcore qcoreapplication="">qApp->exit(2);</qtcore></code>
4.备注
1.atexit函数比较有用mfc上也可以采用这个做重新登录
2.在win7+vs2010+qt5.40编译运行正常
免费领课
热搜文章
最新文章
- 折半查找算法的实现 -电脑资料
- 回调函数应用(冒泡排序 既排整
- thinkphp 关于iis上面中文参数乱
- 自定义SectionAdapter显示数据 -
- java克隆对象clone()的用法和作
- static, enum, 内部类与单例模式
- Java多线程学习(吐血超详细总结
- Java中几个容易混淆的相似概念和
推荐文章
- Java中几个容易混淆的相似概念和
- Struts2基本读写法上传文件 -电
- Java设计模式——工厂模式 -电脑
- AOJ 0118 Property Distribution
- bzoj1305[CQOI2009]dance 跳舞 -
- C# GetHashCode 的实现方式 -电
- 工厂模式 -电脑资料
- 用C++实现一个Log系统 -电脑资料