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

  1. int main(int argc, char** argv)
  2. {
  3. QApplication app(argc, argv);
  4. Widget w;
  5. w.show()
  6. return app.exec();
  7. }

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.

  1. QProcess::startDetached(qApp->applicationFilePath(), QStringList());

if applicationFilePath not continues space char, we can use

  1. QProcess::startDetached(qApp->applicationFilePath());

Example one

  1. qApp->quit();
  2. QProcess::startDetached(qApp->applicationFilePath(), QStringList());

or

  1. qApp->closeAllWindow();
  2. QProcess::startDetached(qApp->applicationFilePath(), QStringList());

Example two

  1. /**773 = 'r'+'e'+'s'+'t'+'a'+'r'+'t' */
  2. qApp->exit(773);
  1. int main(int argc, char** argv)
  2. {
  3. int ret = app.exec();
  4. if (ret == 773) {
  5. QProcess::startDetached(qApp->applicationFilePath(), QStringList());
  6. return 0;
  7. }
  8. return ret;
  9. }

How to Restart Qt Application的更多相关文章

  1. Qt Application Menu In Window and Mac

    Application Menu Application menu in different operator systems has different designed style. like W ...

  2. qt application logging

    “AnalysisPtsDataTool201905.exe”(Win32): 已加载“F:\OpencvProject\ZY-Project\x64\Debug\AnalysisPtsDataToo ...

  3. 更改Qt Application为 Qt Console Application

    工程属性 -> 链接器 -> 系统 -> 子系统 : 更改为 控制台 (/SUBSYSTEM:CONSOLE)

  4. 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 ...

  5. Qt Setting Application Icon

    Qt4 设置应用程序图标 将一个ico图标放在资源文件夹下; 然后建立txt,输入 IDI_ICON1 DISCARABLE "myico.ico"; 保存文件,将其后缀改为.rc ...

  6. 两个基于C++/Qt的开源WEB框架

    1.tufao 项目地址: https://github.com/vinipsmaker/tufao 主页: http://vinipsmaker.github.io/tufao/ 介绍: Tufão ...

  7. 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 ...

  8. 简单的音乐播放器(VS 2010 + Qt 4.8.5)

    昨天历经千辛万苦,配置好了VS 2010中的Qt环境(包括Qt for VS插件),今天决定浅浅地品味一下将两者结合进行编程的魅力. 上网查了一些资料,学习了一些基础知识,决定做一个简单的音乐播放器, ...

  9. [QT]抄—影像显示实验

    QtCreator新建一个Qt Application,命名为ImageView 在项目文件夹下添加gdal库,统一放在ImageView\gdal目录下. 右键单击项目,选择添加库命令,添加gdal ...

随机推荐

  1. Multiple Object Tracking using K-Shortest Paths Optimization简要

    参考文献:Multiple Object Tracking using K-Shortest Paths Optimization 核心步骤: 两步:一.detection 二.link detect ...

  2. supervisor 使用tips

    Supervisor (http://supervisord.org) 是一个用 Python 写的进程管理工具,可以很方便的用来启动.重启.关闭进程,supervisor可以同时监控多个进程,并可以 ...

  3. BZOJ2957: 楼房重建(线段树&LIS)

    2957: 楼房重建 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 3727  Solved: 1793[Submit][Status][Discus ...

  4. .net中的Dictionary字典类的使用方法

    //定义字典 Dictionary<string, string> d = new Dictionary<string, string>(); //添加字典的元素 ; i &l ...

  5. 7-26 Harry Potter's Exam(25 分)

    In Professor McGonagall's class of Transfiguration, Harry Potter is learning how to transform one ob ...

  6. flask第二十三篇——模板【5】过滤器

    请关注微信公众号:自动化测试实战 过滤器——format格式化 flaskDemo.py # coding: utf-8 from flask import Flask, render_templat ...

  7. python自动解析301、302重定向链接

    使用模块requests 方式代码如下: import requests url_string="http://******" r = requests.head(url_stri ...

  8. c# 爬虫(一) HELLO WORLD

    最近在摸索爬虫相关的东西,写点随笔,以便忘记. 目的与用途 现实的项目中,我们需要太多的第三方接口了.而往往这些第三方接口由于条件限制,一时拿不到. 譬如: 1. 淘宝网今天有什么特价商品. 2. 百 ...

  9. 华硕主板P8H61(P8H61-M_LX3_PLUS_R2.0)成功禁用USB口

    公司大批这个型号的主板,在百度上搜索了一下,其中有一篇帖子说华硕客服说这个型号的USB控制XX是集成成南桥上面没法禁止. 经过研究发现官网上的0802版可以支持禁止usb,并且可以根据需要为每一个US ...

  10. Bootstrap-Plugin:插件概览

    ylbtech-Bootstrap-Plugin:插件概览 1.返回顶部 1. Bootstrap 插件概览 在前面 布局组件 章节中所讨论到的组件仅仅是个开始.Bootstrap 自带 12 种 j ...