Fix the closeEvent of the systray example on OS X
The implementation of the close event handler requires handling the two close events that are received on OS X when the user quits through the application menu bar or the Command+Q shortcut. The first is an spontaneous event, and the second a non-spontaneous one with the window already closed. Change-Id: I24e3d3f0de4d631bd2d5616c85ce747f085691e0 Reviewed-by: Topi Reiniö <topi.reinio@digia.com>
This commit is contained in:
parent
0f68f89205
commit
115f303352
@ -173,7 +173,11 @@
|
||||
|
||||
We have reimplemented the QWidget::closeEvent() event handler to
|
||||
receive widget close events, showing the above message to the
|
||||
users when they are closing the editor window.
|
||||
users when they are closing the editor window. On OS X we need to
|
||||
avoid showing the message and accepting the close event when the
|
||||
user really intends to quit the application, that is, when the
|
||||
user has triggered "Quit" in the menu bar or pressed the Command+Q
|
||||
shortcut.
|
||||
|
||||
In addition to the functions and slots discussed above, we have
|
||||
also implemented several convenience functions to simplify the
|
||||
|
@ -102,6 +102,11 @@ void Window::setVisible(bool visible)
|
||||
//! [2]
|
||||
void Window::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
#ifdef Q_OS_OSX
|
||||
if (!event->spontaneous() || !isVisible()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (trayIcon->isVisible()) {
|
||||
QMessageBox::information(this, tr("Systray"),
|
||||
tr("The program will keep running in the "
|
||||
|
Loading…
x
Reference in New Issue
Block a user