From 4ea32eaad0138ee49484780a34bc8d2364c096cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 19 Oct 2021 12:30:35 +0200 Subject: [PATCH] macOS: Wake up event dispatcher after running modal dialog helpers The root event loop may have been exited, so we need to ensure the event dispatcher is woken up so it can evaluate whether it should continue or not. For most applications this happens automatically when e.g. the user moves their mouse or press a key, but for tests this may not be the case, and the test will stall and never exit its event loop. Pick-to: 6.2 Change-Id: Ic241e3f1045481c34150289ff711b921addb18e4 Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm | 5 +++++ src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm | 4 ++++ src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 4e8b87c41c..b21b7c2cc9 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -236,6 +236,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); [NSApp runModalForWindow:mColorPanel]; mDialogIsExecuting = false; + + // Wake up the event dispatcher so it can check whether the + // current event loop should continue spinning or not. + QCoreApplication::eventDispatcher()->wakeUp(); + return (mResultCode == NSModalResponseOK); } diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index e84d50d729..8bd649e461 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -206,6 +206,10 @@ typedef QSharedPointer SharedPointerFileDialogOptions; auto result = [m_panel runModal]; m_helper->panelClosed(result); + + // Wake up the event dispatcher so it can check whether the + // current event loop should continue spinning or not. + QCoreApplication::eventDispatcher()->wakeUp(); } - (void)closePanel diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index 4fa8ea2721..355d658242 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -218,6 +218,11 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); [NSApp runModalForWindow:mFontPanel]; mDialogIsExecuting = false; + + // Wake up the event dispatcher so it can check whether the + // current event loop should continue spinning or not. + QCoreApplication::eventDispatcher()->wakeUp(); + return (mResultCode == NSModalResponseOK); }