Do `quit()` if the system requested the app to close.

This fixes the issue where a system logout was blocked by bitmask since
we were interpreting the closeEvent as if the user clicked on the 'X'
button.
Closes #5870.