summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-15 06:17:32 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-15 11:32:08 +0200
commit983132212c7f3541a8c5fbaf4c5309d92345107f (patch)
tree3c3b7fa5445681a4cf308ffef15be74975ddf330 /src/plugins/platforms/windows
parente96a311334a5c70d5ffcc2ca5c10919952b99636 (diff)
Windows QPA: Fix build with mingw64/Win32 threading
For this build, cxx11_future is not available and thus QThread::create() as introduced by ed114b728d9dc5265333c593254d9f6527464a60 does not work. Revert back to implementing a QThread. Pick-to: 5.15 Fixes: QTBUG-86575 Task-number: QTBUG-85676 Change-Id: I86a91f6bcdfc88804b35bf617362d92f37e51dea Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src/plugins/platforms/windows')
-rw-r--r--src/plugins/platforms/windows/qwindowsservices.cpp32
1 files changed, 25 insertions, 7 deletions
diff --git a/src/plugins/platforms/windows/qwindowsservices.cpp b/src/plugins/platforms/windows/qwindowsservices.cpp
index 8a95cc53a8..f8d2b8f04e 100644
--- a/src/plugins/platforms/windows/qwindowsservices.cpp
+++ b/src/plugins/platforms/windows/qwindowsservices.cpp
@@ -56,6 +56,26 @@ QT_BEGIN_NAMESPACE
enum { debug = 0 };
+class QWindowsShellExecuteThread : public QThread
+{
+public:
+ explicit QWindowsShellExecuteThread(const wchar_t *path) : m_path(path) { }
+
+ void run() override
+ {
+ if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE))) {
+ m_result = ShellExecute(nullptr, nullptr, m_path, nullptr, nullptr, SW_SHOWNORMAL);
+ CoUninitialize();
+ }
+ }
+
+ HINSTANCE result() const { return m_result; }
+
+private:
+ HINSTANCE m_result = nullptr;
+ const wchar_t *m_path;
+};
+
static quintptr runShellExecute(const wchar_t *path)
{
HINSTANCE result = nullptr;
@@ -75,13 +95,11 @@ static inline bool shellExecute(const QUrl &url)
// Run ShellExecute() in a thread since it may spin the event loop.
// Prevent it from interfering with processing of posted events (QTBUG-85676).
- quintptr result = 0;
- quintptr *resultPtr = &result;
- const auto path = reinterpret_cast<const wchar_t *>(nativeFilePath.utf16());
- QScopedPointer<QThread> thread(QThread::create([path, resultPtr]
- () { *resultPtr = runShellExecute(path); }));
- thread->start();
- thread->wait();
+ QWindowsShellExecuteThread thread(reinterpret_cast<const wchar_t *>(nativeFilePath.utf16()));
+ thread.start();
+ thread.wait();
+
+ const auto result = reinterpret_cast<quintptr>(thread.result());
// ShellExecute returns a value greater than 32 if successful
if (result <= 32) {