#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.