Process still exists after closing windows in QT

Source: Internet
Author: User

#include <QApplication> #include <QWidget> int main (int argc, char *argv[]) {qapplication app (argc, argv); Qwidget *window = new Qwidget; Window->shownormal (); Window->setattribute (Qt::wa_deleteonclose, true); Window->close (); return App.exec (); }

It's meant to be the widget closed, and the program should exit normally.

But actually the process is still running.

The exit of the app in Qt defaults to exit automatically when the last window closes

You can change it by setquitonlastwindowclosed.

Documentation about the close () function

Closes this widget. Returns true if the widget was closed; otherwise returns false.

The IT sends the widget a qcloseevent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of Qwidget::closeevent () accepts the close event.

If The widget has the Qt::wa_deleteonclose flag, the widget is also deleted. A Close the events are delivered to the widget no matter if the widget was visible or not.

The qapplication::lastwindowclosed () signal is emitted then the last visible primary window (i.e. windows with no parent) W ITH the Qt::wa_quitonclose set is closed. By default this attribute is set to all widgets except transient windows such as splash screens, tool windows, and Popup Menus.

The red section generates a qapplication::lastwindowclosed () signal when the last window is closed, and it is the signal that causes the program to exit.
But when the Windows.close () is invoked, the program does not enter the message loop, and the operating system is a message response,
The slot corresponding to the qapplication::lastwindowclosed () signal should not be executed.
And so after the program into App.exec (), never Quit () execution, equivalent to the death cycle into the

And why does the above code call the Close () method in that place. (no reason to be bored) before entering App.exec (), the widgets created can be closed and automatically shut down when the program is finished.

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.