diff --git a/src/corelib/kernel/qfunctions_win.cpp b/src/corelib/kernel/qfunctions_win.cpp index 048fdbc934c..4c057cdb2c5 100644 --- a/src/corelib/kernel/qfunctions_win.cpp +++ b/src/corelib/kernel/qfunctions_win.cpp @@ -33,6 +33,23 @@ QComHelper::~QComHelper() CoUninitialize(); } +/*! + \internal + Make sure the COM library is is initialized on current thread. + + Initializes COM as a single-threaded apartment on this thread and + ensures that CoUninitialize will be called on the same thread when + the thread exits. Note that the last call to CoUninitialize on the + main thread will always be made during destruction of static + variables at process exit. + + https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/modernize-packaged-apps +*/ +void qt_win_ensureComInitializedOnThisThread() +{ + static thread_local QComHelper s_comHelper; +} + /*! \internal Checks if the application has a \e{package identity} diff --git a/src/corelib/kernel/qfunctions_win_p.h b/src/corelib/kernel/qfunctions_win_p.h index ab5417f8a25..e8cc57cc84a 100644 --- a/src/corelib/kernel/qfunctions_win_p.h +++ b/src/corelib/kernel/qfunctions_win_p.h @@ -42,6 +42,8 @@ private: DWORD m_threadId{ GetCurrentThreadId() }; }; +Q_CORE_EXPORT void qt_win_ensureComInitializedOnThisThread(); + Q_CORE_EXPORT bool qt_win_hasPackageIdentity(); QT_END_NAMESPACE