qt实现重新登录
2015-07-14 17:33
351 查看
1.需求
需要实现程序操作过程中的重新启动,即经常说的重新登录功能
2.解决
在main函数中检测exec的返回值决定是关闭还是重启,使用注册函数atexit(relogin)来实现这个功能
3.代码
main.cpp
#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); }
函数调用
#include <QtCore/QCoreApplication> qApp->exit(2);
4.备注
1.atexit函数比较有用mfc上也可以采用这个做重新登录
2.在win7+vs2010+qt5.40编译运行正常
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt定时器和随机数详解
- Qt实现图片移动实例(图文教程)
- Qt for Android开发实例教程
- QModelIndex/Role/Model介紹<二>
- 基于PyQt5的快速开发框架QFramer
- ok6410开发板移植DirectFB手记
- 【笔记】给Qt内嵌一个Chrome吧
- 【算法】最短路径之A*搜索
- qt入门必备
- 在 Qt4 中使用 C++11
- Hello Word ~ v0.2.2 背单词软件发布 -- By WHYPRO
- ubuntu下opencv和qt的安装配置
- linux下opengl的安装(with qt)
- qt 学习小节
- QT的命名风格
- QT 中的sleep
- QT 串口的监控
- 在VS2010下配置QT和ITK+VTK