I'm looking for a documentation about the things that happen after/while calling the quit() of a Qt application. The question stems from a problem that I had with handling return values of open QDialogs on quit(). I would like to clarify the following sequence:
- QCoreApplication::quit() or QApplication::quit() is called
- QWidget::closeEvent() is not called for QDialogs. It seems that all open dialogs are automatically closed by calling their reject() method. This is the most important part, is this behavior guaranteed?
- The "event-loop-blocking" QDialog::exec() methods return which have to be carefully handled by the caller (access of members of already deleted objects,...).
- The aboutToQuit signal is emitted
- The destructor of the application is called
So the program flow is: As long as a modal dialog is open the event loop of this dialog is running. When quit() is called QDialog::exec() (the event loop of the modal dialog) is returning which could mean that a lot of additional code is run and even signal/slots could be executed when they are in the same thread. Then the normal event loop is not processed anymore, just aboutToQuit() and the destructors are called.
Is this description correct? Can someone point me to a Qt documentation that explains the interaction of quit() and QDialog? And what happens when I call exec() of a QDialog after a exec() of QDialog returned due to the quit() call? Who is then closing this QDialog?
Thanks, I'm a bit confused about all those interactions.
Edit: It appears that calls to exec() of a QDialog are rejected if the quit() method was called before. So I guess that Qt internally knows that the application is about to quit so all further QDialogs return "rejected" immediately.
I am not sure what you mean with "closeEvent is not called for QDialogs" because that is where it calls
reject()
: QDialog::closeEvent() codeAs for the interaction between various
exec()
andquit()
:QDialog::exec()
uses a nestedQEventLoop
: QDialog::exec() codeQCoreApplication::quit()
loops through all nested event loops on tells them to exit: QCoreApplication::exec() code