Skip to content

Commit fcddecc

Browse files
committed
oshelper: wait for hidden window before taking screenshot on macOS
Also improve error message and add a missing include.
1 parent 26b6902 commit fcddecc

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/oshelper.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "oshelper.h"
3030

31+
#include <algorithm>
3132
#include <unordered_set>
3233

3334
#include <QCoreApplication>
@@ -39,11 +40,13 @@
3940
#include <QDir>
4041
#include <QDebug>
4142
#include <QDesktopServices>
43+
#include <QEventLoop>
4244
#include <QFileInfo>
4345
#include <QString>
4446
#include <QUrl>
4547
#include <QByteArray>
4648
#include <QRandomGenerator>
49+
#include <QThread>
4750
#ifdef Q_OS_MAC
4851
#include "qt/macoshelper.h"
4952
#endif
@@ -74,6 +77,14 @@ QPixmap screenshot()
7477
window->hide();
7578
}
7679
}
80+
81+
#if defined(Q_OS_MAC)
82+
// Let Qt submit the native hide operations before blocking the GUI thread.
83+
QGuiApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
84+
// Give WindowServer time to finish removing the window.
85+
QThread::msleep(100);
86+
#endif
87+
7788
const auto unhide = sg::make_scope_guard([&hidden]() {
7889
for (QWindow *window : hidden)
7990
{
@@ -144,7 +155,7 @@ QList<QString> OSHelper::grabQrCodesFromScreen() const
144155
}
145156
catch (const std::exception &e)
146157
{
147-
qWarning() << e.what();
158+
qWarning() << "QR screen capture: decoder exception:" << e.what();
148159
}
149160

150161
return codes;

0 commit comments

Comments
 (0)