From 8c3ae221e60ae9b15ed5b942c18a52c2c0f3014f Mon Sep 17 00:00:00 2001 From: Maurice Kalinowski Date: Fri, 16 Jan 2015 11:29:54 +0100 Subject: 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 --- src/corelib/kernel/qcoreapplication.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/corelib/kernel') diff --git a/src/corelib/kernel/qcoreapplication.cpp b/src/corelib/kernel/qcoreapplication.cpp index ca3d92bad1..6b0ebf8b8b 100644 --- a/src/corelib/kernel/qcoreapplication.cpp +++ b/src/corelib/kernel/qcoreapplication.cpp @@ -81,6 +81,11 @@ #ifdef Q_OS_WIN # ifdef Q_OS_WINRT # include "qeventdispatcher_winrt_p.h" +# include "qfunctions_winrt.h" +# include +# include + 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 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 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 } /***************************************************************************** -- cgit v1.2.3