WinRT: Gracefully exit an application

While it is not recommended by Microsoft to manually exit an
application, currently applications just hang when exiting main().

Instead when QCoreApplication::exit() is called use the CoreApplication
to properly invoke native Exit() and let the application completely shut
down.

Add a warning to notify developer about this non-standard behavior, as
usually the system is supposed to take care of suspending and closing.

Certification still passes for Windows RT and Windows Phone.

Task-number: QTBUG-43862
Change-Id: Ia34443ea75daaaeca0bee2a0c9fcc568c0659262
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
This commit is contained in:
Maurice Kalinowski 2015-01-16 11:29:54 +01:00 committed by Jani Heikkinen
parent 5f6bbce4be
commit 8c3ae221e6

View File

@ -81,6 +81,11 @@
#ifdef Q_OS_WIN
# ifdef Q_OS_WINRT
# include "qeventdispatcher_winrt_p.h"
# include "qfunctions_winrt.h"
# include <wrl.h>
# include <Windows.ApplicationModel.core.h>
using namespace ABI::Windows::ApplicationModel::Core;
using namespace Microsoft::WRL;
# else
# include "qeventdispatcher_win_p.h"
# endif
@ -1221,6 +1226,19 @@ void QCoreApplication::exit(int returnCode)
QEventLoop *eventLoop = data->eventLoops.at(i);
eventLoop->exit(returnCode);
}
#ifdef Q_OS_WINRT
qWarning("QCoreApplication::exit: It is not recommended to explicitly exit an application on Windows Store Apps");
ComPtr<ICoreApplication> app;
HRESULT hr = RoGetActivationFactory(Wrappers::HString::MakeReference(RuntimeClass_Windows_ApplicationModel_Core_CoreApplication).Get(),
IID_PPV_ARGS(&app));
RETURN_VOID_IF_FAILED("Could not acquire ICoreApplication object");
ComPtr<ICoreApplicationExit> appExit;
hr = app.As(&appExit);
RETURN_VOID_IF_FAILED("Could not acquire ICoreApplicationExit object");
hr = appExit->Exit();
RETURN_VOID_IF_FAILED("Could not exit application");
#endif // Q_OS_WINRT
}
/*****************************************************************************