diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 94904c12f63884e61e121520ec0a5e39206221b7..30c2a99fd870dad36564b51a2bf2a037cb0d2648 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -320,9 +320,10 @@ void QCocoaWindow::setVisible(bool visible)
         // - QNSViews for child windows are initialy not hidden and won't get the
         //   viewDidUnhide message.
         exposeWindow();
-        QWindowSystemInterface::flushWindowSystemEvents();
 
         if (m_nsWindow) {
+            QWindowSystemInterface::flushWindowSystemEvents();
+
             // setWindowState might have been called while the window was hidden and
             // will not change the NSWindow state in that case. Sync up here:
             syncWindowState(window()->windowState());