zoukankan      html  css  js  c++  java
  • 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;
    }
    

  • 相关阅读:
    rxjs 学习实践笔记
    封装localStorage、sessionStorage设置,获取,移除方法
    Angular实现类似vuex状态管理功能、全局数据管理与同步更新
    关于RxJS 处理多个Http请求 串行与并行方法
    vue插件汇总
    vue使用videojs控制后台m3u8数据请求
    NPOI winform读取Excel
    //邮件发送:
    定时任务框架Quartz.net
    系统日志控件 Log4NET
  • 原文地址:https://www.cnblogs.com/zi-xing/p/8639580.html
Copyright © 2011-2022 走看看