When I try to close my Qt program, it just keeps running in the background though there's no window anymore.
Basically, I would like to know what I should do so it closes properly when I click the red cross on my main window (which has no parent).
Following this link, I tried a few things like :
QApplication app(argc, argv);
//...
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
return app.exec();
or
QApplication app(argc, argv);
//...
app.setQuitOnLastWindowClosed(true);
return app.exec();
but neither work, the process still stays in memory, after the cross is clicked.
Then, how can I close correctly my program ?
You can close your application manually using QApplication::quit()
.
By default the execution is terminated when the last top level window with the Qt::WA_QuitOnClose
attribute has been closed. You don't need to connect lastWindowClosed
to quit
because it repeats the default setQuitOnLastWindowClosed
behavior. You don't need to do setQuitOnLastWindowClosed(true)
either because it's true by default. The code you've posted does nothing (if nothing is changed somewhere else).
Possible solutions:
Qt::WA_QuitOnClose
attribute.closeEvent
in your top level window, check that close event is being accepted. QApplication::topLevelWidgets()
to list them.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With