Qt Qapplication after the exit,quit call still shows the window

Source: Internet
Author: User
First, let's talk about the function of these two functions. Two functions are used to exit the application, but the difference is that exit can take one parameter, you can set the exit flag, and quit is the equivalent of calling exit (0).
However, I found that after making the following call, I did not exit the program.

int main (int argc, char *argv[])
{
Qapplication A (argc, argv);
Logindialog Dlg;
Dlg.exec ();
if (dlg. Getlogstate () = = False)
Qapplication::exit ();
MainWindow W;
W.show ();
W.close ();
return A.exec ();
}

In the program I first pop up a login box, and then get the login status, if the login failed, then quit the program, otherwise display the main interface. After running, the main interface is displayed even if the login fails. After reviewing the QT documentation, I found that the problem should be related to the use of events prior to A.exec (). The Exec start time loop, while the event loop in the previously invoked dialog box cannot be processed to the application's quit event.
Of course, here is the simplest solution, if the login fails, let the main function return directly, instead of constructing the display main interface, do not open the application event loop. In other places after the event loop starts, such as the main interface can be clicked Exit button to exit, etc., you can call Qapplication::exit (0) or quit to exit.
To end up with a sentence, the call to exit and quit is not valid until the event loop is opened and is ignored.

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.