summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qeventdispatcher_winrt.cpp
diff options
context:
space:
mode:
authorAndrew Knight <andrew.knight@digia.com>2014-08-11 00:35:47 +0300
committerAndrew Knight <andrew.knight@digia.com>2014-08-11 23:29:27 +0200
commit34198cedbed52d5eb1aa4612b0a162c8a8a9b63a (patch)
tree2185f2567b60b246de513b48fcfb886bbd6601a2 /src/corelib/kernel/qeventdispatcher_winrt.cpp
parent57d9eb2b773705a21470de47464a60f6594fb49a (diff)
winrt: Fix core dispatcher lookup
The core dispatcher lookup should be performed from the constructor in all cases but the first (WinMain) thread, and only rechecked if the thread changes. Change-Id: I05f0c15b3e199994aa5d740b2092b42fb8d2f596 Reviewed-by: Oliver Wolff <oliver.wolff@digia.com>
Diffstat (limited to 'src/corelib/kernel/qeventdispatcher_winrt.cpp')
-rw-r--r--src/corelib/kernel/qeventdispatcher_winrt.cpp52
1 files changed, 33 insertions, 19 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_winrt.cpp b/src/corelib/kernel/qeventdispatcher_winrt.cpp
index c601b4cea1..c8f959a962 100644
--- a/src/corelib/kernel/qeventdispatcher_winrt.cpp
+++ b/src/corelib/kernel/qeventdispatcher_winrt.cpp
@@ -136,11 +136,42 @@ private:
QPointer<QThread> thread;
bool interrupt;
+
+ void fetchCoreDispatcher()
+ {
+ ComPtr<ICoreImmersiveApplication> application;
+ HRESULT hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(),
+ IID_PPV_ARGS(&application));
+ RETURN_VOID_IF_FAILED("Failed to get the application factory");
+
+ ComPtr<ICoreApplicationView> view;
+ hr = application->get_MainView(&view);
+ RETURN_VOID_IF_FAILED("Failed to get the main view");
+
+ ComPtr<ICoreWindow> window;
+ hr = view->get_CoreWindow(&window);
+ RETURN_VOID_IF_FAILED("Failed to get the core window");
+
+ hr = window->get_Dispatcher(&coreDispatcher);
+ RETURN_VOID_IF_FAILED("Failed to get the core dispatcher");
+
+ thread = QThread::currentThread();
+ }
};
QEventDispatcherWinRT::QEventDispatcherWinRT(QObject *parent)
: QAbstractEventDispatcher(*new QEventDispatcherWinRTPrivate, parent)
{
+ Q_D(QEventDispatcherWinRT);
+
+ // Special treatment for the WinMain thread, as it is created before the UI
+ static bool firstThread = true;
+ if (firstThread) {
+ firstThread = false;
+ return;
+ }
+
+ d->fetchCoreDispatcher();
}
QEventDispatcherWinRT::QEventDispatcherWinRT(QEventDispatcherWinRTPrivate &dd, QObject *parent)
@@ -155,25 +186,8 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags)
{
Q_D(QEventDispatcherWinRT);
- if (d->thread != QThread::currentThread()) {
- ComPtr<ICoreImmersiveApplication> application;
- HRESULT hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(),
- IID_PPV_ARGS(&application));
- RETURN_FALSE_IF_FAILED("Failed to get the application factory");
-
- ComPtr<ICoreApplicationView> view;
- hr = application->get_MainView(&view);
- RETURN_FALSE_IF_FAILED("Failed to get the main view");
-
- ComPtr<ICoreWindow> window;
- hr = view->get_CoreWindow(&window);
- RETURN_FALSE_IF_FAILED("Failed to get the core window");
-
- hr = window->get_Dispatcher(&d->coreDispatcher);
- RETURN_FALSE_IF_FAILED("Failed to get the core dispatcher");
-
- d->thread = QThread::currentThread();
- }
+ if (d->thread != QThread::currentThread())
+ d->fetchCoreDispatcher();
bool didProcess = false;
forever {