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>
This commit is contained in:
parent
57d9eb2b77
commit
34198cedbe
@ -136,11 +136,42 @@ private:
|
|||||||
QPointer<QThread> thread;
|
QPointer<QThread> thread;
|
||||||
|
|
||||||
bool interrupt;
|
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)
|
QEventDispatcherWinRT::QEventDispatcherWinRT(QObject *parent)
|
||||||
: QAbstractEventDispatcher(*new QEventDispatcherWinRTPrivate, 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)
|
QEventDispatcherWinRT::QEventDispatcherWinRT(QEventDispatcherWinRTPrivate &dd, QObject *parent)
|
||||||
@ -155,25 +186,8 @@ bool QEventDispatcherWinRT::processEvents(QEventLoop::ProcessEventsFlags flags)
|
|||||||
{
|
{
|
||||||
Q_D(QEventDispatcherWinRT);
|
Q_D(QEventDispatcherWinRT);
|
||||||
|
|
||||||
if (d->thread != QThread::currentThread()) {
|
if (d->thread != QThread::currentThread())
|
||||||
ComPtr<ICoreImmersiveApplication> application;
|
d->fetchCoreDispatcher();
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool didProcess = false;
|
bool didProcess = false;
|
||||||
forever {
|
forever {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user