From 983132212c7f3541a8c5fbaf4c5309d92345107f Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Tue, 15 Sep 2020 06:17:32 +0200 Subject: 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 --- src/plugins/platforms/windows/qwindowsservices.cpp | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'src') 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(nativeFilePath.utf16()); - QScopedPointer thread(QThread::create([path, resultPtr] - () { *resultPtr = runShellExecute(path); })); - thread->start(); - thread->wait(); + QWindowsShellExecuteThread thread(reinterpret_cast(nativeFilePath.utf16())); + thread.start(); + thread.wait(); + + const auto result = reinterpret_cast(thread.result()); // ShellExecute returns a value greater than 32 if successful if (result <= 32) { -- cgit v1.2.3