Why does this program run normally and display the main window? I would expect it to exit since quit()
is called in the constructor.
Main.cpp:
#include<QApplication>
#include"MainWindow.h"
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
MainWindow mainWindow;
mainWindow.show();
return app.exec();
}
MainWindow.cpp:
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
qApp->quit();
}
void MainWindow::closeEvent(QCloseEvent *)
{
qDebug("Hello world!");
}
See Question&Answers more detail:os