qt的close和quit,一个是用来关闭窗口的,一个是用来关闭程序的,但是他们之间也有关系。qt手册里有
Closes this widget. Returns true if the widget was closed; otherwise returns false.
First 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 events is delivered to the widget no matter if the widget is visible or not.
The QApplication::lastWindowClosed() signal is emitted when the last visible primary window (i.e. window with no parent) with the Qt::WA_QuitOnClose attribute set is closed. By default this attribute is set for all widgets except transient windows such as splash screens, tool windows, and popup menus.
很明显,close只是隐藏了窗口,只有当最后一个可见窗口close的时候,他会emit一个信号QApplication::lastWindowClosed(),这个信号发射之后,会有以下情况:
This signal is emitted from exec() when the last visible primary window (i.e. window with no parent) is closed.
By default, QGuiApplication quits after this signal is emitted. This feature can be turned off by setting quitOnLastWindowClosed to false.
就是说,这信号emit之后,QGuiApplication quits,于是程序退出。