Solve the problem that the embedded QT program closes the window after the process does not end

Source: Internet
Author: User

Develop the interface with QT4.8.6 on HiSilicon 3536 chip. GUI program is a form, in the terminal with the command line to start, instructions such as XXXX-QWS, and then click on the fork close the form, the form disappears, but the terminal command line instructions do not return, with PS view found that the process did not exit. The same code is compiled using the QT library on the PC, which is normally shut down on the PC, so it is speculated that this problem is related to QWS. By debugging the main function, it is found that the process is stuck in the destructor of Qapplication. The project for this program is created with Qt Creator, and the default main function is as follows:

int main (int argc, char *argv[])
{
Qapplication A (argc, argv);

MainWindow W;
W.show ();

return A.exec ();
}

This qapplication instance is declared as a local variable, to be destructor when the main function releases the stack, and the reason for the suspected card death is that some QWS related resources have a problem with the release order. So I use the dynamic allocation method to generate Qapplication instances, and modify the code as follows:

int main (int argc, char *argv[])
{
Qapplication *p = qapplication (argc, argv);

if (!p)

{

return-1;

}

MainWindow W;
W.show ();

int ret;

ret = P->exec ();

Delete p;

return ret;
}

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.