先写下重点
QApplication::quitOnLastWindowClosed
以下是对于QApplication中此属性的解释:
This property holds whether the application implicitly quits when the last window is closed.
The default is true.
If this property is true, the applications quits when the last visible primary window (i.e. window with no parent) is closed.
quitOnLastWindowClosed这个属性决定最后一个window关闭时,程序是否会退出(quick)。此属性的默认值为true。如果为true,程序会在最后一个可视主窗口(比如:一个没有parent的window)关闭时退出。
问题来了
下面是一个例子:
/*mainwindow.cpp*/
#include "mainwindow.h"
#include
#include
#include
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QPushButton *button = new QPushButton();
button->setText("Click to open file-dialog");
connect(button, &QPushButton::clicked, [=]{ </