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 callQCoreApplication::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;
}

原文地址:https://www.cnblogs.com/zi-xing/p/8639580.html

时间: 2024-10-14 19:23:07

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 Windows and Mac os, they are different.In the code, we can use different Macro ,eg:Q_OS_MAC and Q_OS_WIN #ifdef Q_OS_MAC void MainWindow::InitMenu() {

qt application logging

“AnalysisPtsDataTool201905.exe”(Win32): 已加载“F:\OpencvProject\ZY-Project\x64\Debug\AnalysisPtsDataTool201905.exe”.已加载符号.“AnalysisPtsDataTool201905.exe”(Win32): 已加载“C:\Windows\System32\ntdll.dll”.无法查找或打开 PDB 文件.“AnalysisPtsDataTool201905.exe”(Win32): 已

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 a simplified version of the Qt UI Tools Text Finder Example. The application user interface is constructed from Qt widgets by using Qt Designer. The a

QT Demo 之 window(5) window.qml

在分析了main.cpp.Splash.Qt.quit()以及ScreenInfo之后,我们终于开始了正题:window.qml. window.qml的主体结构 window.qml主体是一个QtObject,其中包含了4个子元素:palette.controlWindow.testWindow和splashWindow: QtObject { property real defaultSpacing: 10 property SystemPalette palette: SystemPale

VS2008下QT整合OGRE

环境配置如下:VS2008 QT版本:4.8.1 OGRE版本: 1.7.4 请先配置好QT  for vs2008  : 下载QT VS2008的包,然后下个QT VS的插件 版本必须是VS2008或VS2010 不能是精简版 新建一个QT Application 新建环境变量:$(OGRE)指向你的OGRE目录, 选择:工具-选项-项目和解决方案-VC++目录 -选择包含文件下拉选项 增加 $(OGRE)\boost_1_48\boost 和 $(OGRE)\include\OGRE 选择库

基于QT开发的第三方库

基于Qt开发的第三方库 分类: Qt2014-02-12 11:34 1738人阅读 评论(0) 收藏 举报 QT第三方库 目录(?)[+] 文章来源:http://blog.csdn.net/zhgn2/article/details/14613519 QxOrm QxOrm is a new open source ORM (Object Relational Mapping) C++ library designed to provide : * Persistence (based on

Top Things to Consider When Troubleshooting Complex Application Issues

http://blogs.msdn.com/b/debuggingtoolbox/archive/2011/10/03/top-things-to-consider-when-troubleshooting-complex-application-issues.aspx 1- For reactive incidents: “Bring the engineer onsite because it is going to be easier to isolate the problem.” Th

VS 2013+Qt 5.4.1

Qt应用能够用Qt Creator开发,也能够使用Visual Studio. 我之前一直用Qt Creator.也始终认为这是最好的选择.只是有人偏爱Visual Studio,我也由于工作须要,要使用Visual Studio来开发Qt应用.记录一下安装配置过程. 资源下载和安装 须要下列资源: Visual Studio 2013 Qt SDK 5.4.1(qt-opensource-windows-x86-msvc2013_64-5.4.1.exe).这是Qt SDK.开发Qt应用必须的

树莓派中安装QT

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 环境: 主机:WIN7 硬件:树莓派 步骤: 参考链接:http://qt-project.org/wiki/apt-get_Qt4_on_the_Raspberry_Pi Firstly I got the development tools needed by Qt Creator in the hope it would be less heavy for the Pi to download