summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreapplication.cpp
diff options
context:
space:
mode:
authorMaurice Kalinowski <maurice.kalinowski@theqtcompany.com>2015-01-16 11:29:54 +0100
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2015-02-02 10:26:47 +0000
commit8c3ae221e60ae9b15ed5b942c18a52c2c0f3014f (patch)
tree48f093c7306e6f5f59ac1b9740aac72e5b8a985a /src/corelib/kernel/qcoreapplication.cpp
parent5f6bbce4beb32bc6bc1e06f92cde56c48f946558 (diff)
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>
Diffstat (limited to 'src/corelib/kernel/qcoreapplication.cpp')
-rw-r--r--src/corelib/kernel/qcoreapplication.cpp18
1 files changed, 18 insertions, 0 deletions
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 <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
}
/*****************************************************************************