how to restart my own qt application ?

how to restart my own qt application ?

Asked on January 8, 2019 in Qt.
Add Comment


  • 3 Answer(s)

    Restart my own qt appliactions:

    #include <QApplication>
    #include <QProcess>
     
    ...
     
    // restart:
    qApp->quit();
    QProcess::startDetached(qApp->arguments()[0], qApp->arguments())
    
    Answered on January 8, 2019.
    Add Comment

    Here the solution is:

    The qt applications are ; after the while statement of a do { … } while( … ); .

    int main(int argc, char *argv[])
    {
        const int RESTART_CODE = 1000;
       
        do
        {
            QApplication app(argc, argv);
            MainWindow main_window(app);
        } while( app.exec() == RESTART_CODE);
       
        return return_from_event_loop_code;
    }
    
    Answered on January 8, 2019.
    Add Comment

    Alternative code is:

    main.cxx
    int main(int argc, char * argv[])
    {
        int result = 0;
     
        do
        {
            QCoreApplication coreapp(argc, argv);
            MyClass myObj;
            result = coreapp.exec();
        } while( result == 1337 );
       
        return result;
    }
    

    Class.cxx

    qApp->exit(1337);
    

     

    Answered on January 8, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.