From 62d0a59ccbe5d2effb978cf2e0aaae108254a3aa Mon Sep 17 00:00:00 2001 From: selsta Date: Sun, 19 Jul 2026 20:40:32 +0200 Subject: [PATCH] oshelper: wait for hidden window before taking screenshot on macOS Also improve error message and add a missing include. --- src/main/oshelper.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/oshelper.cpp b/src/main/oshelper.cpp index 5d517b91fa..38f69fa659 100644 --- a/src/main/oshelper.cpp +++ b/src/main/oshelper.cpp @@ -28,6 +28,7 @@ #include "oshelper.h" +#include #include #include @@ -45,6 +46,8 @@ #include #include #ifdef Q_OS_MAC +#include +#include #include "qt/macoshelper.h" #endif #ifdef Q_OS_WIN @@ -74,6 +77,14 @@ QPixmap screenshot() window->hide(); } } + +#if defined(Q_OS_MAC) + // Let Qt submit the native hide operations before blocking the GUI thread. + QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents); + // Give WindowServer time to finish removing the window. + QThread::msleep(100); +#endif + const auto unhide = sg::make_scope_guard([&hidden]() { for (QWindow *window : hidden) { @@ -144,7 +155,7 @@ QList OSHelper::grabQrCodesFromScreen() const } catch (const std::exception &e) { - qWarning() << e.what(); + qWarning() << "QR screen capture: decoder exception:" << e.what(); } return codes;