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 call QCoreApplication::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 Application
In 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());
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;
}
How to Restart Qt Application的更多相关文章
- Qt Application Menu In Window and Mac
Application Menu Application menu in different operator systems has different designed style. like W ...
- qt application logging
“AnalysisPtsDataTool201905.exe”(Win32): 已加载“F:\OpencvProject\ZY-Project\x64\Debug\AnalysisPtsDataToo ...
- 更改Qt Application为 Qt Console Application
工程属性 -> 链接器 -> 系统 -> 子系统 : 更改为 控制台 (/SUBSYSTEM:CONSOLE)
- Create a Qt Widget Based Application—Windows
This turtorial describes how to use Qt Creator to create a small Qt application, Text Finder. It is ...
- Qt Setting Application Icon
Qt4 设置应用程序图标 将一个ico图标放在资源文件夹下; 然后建立txt,输入 IDI_ICON1 DISCARABLE "myico.ico"; 保存文件,将其后缀改为.rc ...
- 两个基于C++/Qt的开源WEB框架
1.tufao 项目地址: https://github.com/vinipsmaker/tufao 主页: http://vinipsmaker.github.io/tufao/ 介绍: Tufão ...
- Compile Graphics Magick, Boost, Botan and QT with MinGW64 under Windows 7 64
Compile Graphics Magick, Boost, Botan and QT with MinGW64 under Windows 7 64 Sun, 01/01/2012 - 15:43 ...
- 简单的音乐播放器(VS 2010 + Qt 4.8.5)
昨天历经千辛万苦,配置好了VS 2010中的Qt环境(包括Qt for VS插件),今天决定浅浅地品味一下将两者结合进行编程的魅力. 上网查了一些资料,学习了一些基础知识,决定做一个简单的音乐播放器, ...
- [QT]抄—影像显示实验
QtCreator新建一个Qt Application,命名为ImageView 在项目文件夹下添加gdal库,统一放在ImageView\gdal目录下. 右键单击项目,选择添加库命令,添加gdal ...
随机推荐
- bag of words
参考文献 Bag-of-words model (BoW model) 最早出现在NLP和IR领域. 该模型忽略掉文本的语法和语序, 用一组无序的单词(words)来表达一段文字或一个文档. 近年来, ...
- @Transactional、Spring的声明式事务
传送门 一.Spring的声明式事务 需要在xml文件中配置 <!--配置事务管理器类--> <bean id="transactionManager" clas ...
- 【转载】一张表看懂LTE和5G NR的区别
转自:微信公众号:网优雇佣军 KPI 物理层
- [TopCoder12141]SweetFruits
vjudge description 有\(n\)个水果,有一些水果是香的,它们各有一个香度值,剩下的水果是不香的. 现在你要把这\(n\)个水果连成一棵树,定义一个水果是真香的当且仅当它是香的且他与 ...
- sourcetree回退到历史节点
1. 原理 原理,我们都知道Git是基于Git树进行管理的,要想要回滚必须做到如下2点: 本地头节点与远端头节点一样(Git提交代码的前提条件):于本地头节点获取某次历史节点的更改.说的有点抽象,以图 ...
- Python学习思维导图
刚学习Python时,边学边总结的,采用思维导图的形式, 适合回顾使用.内容参考<Python:从入门到实践>一书. 再给出一张Datacamp网站上的一张关于Python基础的总结 ...
- 使用PL/SQL Developer连接远程数据
本机不安装Oracle客户端,使用PL/SQL Developer连接远程数据 1.先到Oracle网站下载Instant Client : http://www.oracle.com/technet ...
- 【转】inittab文件
原文网址:http://blog.csdn.net/shuaishuai80/article/details/6202482 一.inittab文件背景(1)init进程的作用 使用uboot下载 ...
- python 常见问题总结
1.ModuleNotFoundError: No module named 'urllib2' 在python3.x版本中,urllib和urllib2包集合成在一个包了import urllib2 ...
- MYSQL中写SQL语句,取到表中按ID降序排列(最新纪录排在第一行)
'select * from bugdata where id>0 order by id desc'