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的更多相关文章

  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. 集合(List、Set、Map)

    List,Set是继承自Collection接口,Map不是 public interface List<E> extends Collection<E> { public i ...

  2. 浅谈iOS学习之路(转)

    转眼学习iOS已经快两年的时间了,这个路上有挫折也有喜悦,一步步走过来发现这个过程是我这一辈子的财富,我以前的老大总是对我说,年轻就是最大的资本(本人91年),现在才算是慢慢的体会到,反观自己走过的这 ...

  3. mediawikide

    wiki.conf server { listen 80; server_name wiki.talkvip.cn; index index.html index.htm index.php; roo ...

  4. SlickEdit V21 2016 破解教程,win linux mac

    最近主要工作系统转到LInux上面来了,Slickedit的安装破解也费了些事,今天将过程整理一下做个记录. 说明:SlickEdit pro V21.03 Linux 64位实测可用,MAC实测可用 ...

  5. Bootstrap-Plugin:提示工具(Tooltip)插件

    ylbtech-Bootstrap-Plugin:提示工具(Tooltip)插件 1.返回顶部 1. Bootstrap 提示工具(Tooltip)插件 当您想要描述一个链接的时候,提示工具(Tool ...

  6. [Android] 开发第十天

    这几天因为电脑的 USB口发生故障,一直没怎么玩 Android-Studio 后来把电脑从  Win7 -> Win10 重装后,一部分 USB口 可以使用了,然后接着开发 Android 接 ...

  7. [bat]批处理删默认共享和清理垃圾

    @echo off net share c$ /del net share d$ /del net share e$ /del net share f$ /del net share g$ /del ...

  8. [转]Acrylic DNS Proxy 使用方法

    本文转自:http://www.cnwyw.net/index.php/acrylic-dns-proxy-ping-bi-guang-gao/ 从开始菜单进行“Edit Configuration ...

  9. 根据插件Swipe,结合jQuery封装成的新的jQuery插件

    swipe支持电脑上的自动滑动,也支持手机端的滑动效果.但是每次调用只能支持一个效果或者说一个页面出现n个这样的效果,我们就得调用n次这个插件. 我使用swipe+jQuery使得swip变得方便使用 ...

  10. shell编程: 获得目录下(包括子目录)所有文件名,路径和文件大小

    转自:http://blog.chinaunix.net/uid-26000296-id-3575475.html function ergodic(){ ` do "/"$fil ...