QT Restart Application

Source: Internet
Author: User
Scenario One: Restart via process
void mainwindow::on_pushbutton_clicked ()
{
    //qapp->quit ();
    Qapp->closeallwindows (); Closing multiple windows is better than calling quit because the window can accept the Close event

    //If it is on an embedded arm board, you need to add-qws parameter
    //qstringlist args;
    Args.append ("-qws");  parameter information
    //args.append ("&");  Background Run
    //qprocess::startdetached (Qapp->applicationfilepath ());//The Path of the program is not a space or Chinese can also be used
    Qprocess::startdetached (Qapp->applicationfilepath (), qstringlist ());
}

Note: because Qapp, need to include header file # include <QApplication> scenario two: Restart via event loop

void mainwindow::on_pushbutton_2_clicked ()
{
    //  773 = ' R ' + ' E ' + ' s ' + ' t ' + ' a ' + ' r ' + ' t '
    /  = = >restart
    //#define Exit_restart  773
    qapp->exit (773);
}
int main (int argc, char *argv[])
{
    qapplication A (argc, argv);

    int ret =-1;
    Do
    {
        MainWindow w;
        W.show ();

        ret = A.exec ();

    } while (ret! = 0);

    return ret;
}

Note: GIF frame count reason, event cycle restart too fast, recording effect is not obvious, has actually restarted

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.