From 465e7475563db168af60251e43e5e770f3e665b8 Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Wed, 2 Jun 2021 07:05:25 +0300 Subject: Add Co(Un)Initialize call to windows backend The sensors are accessed through the COM library which requires that the initialization routines are done. Task-number: QTBUG-92510 Change-Id: Idf65b0076432bebbab0de9f24b5e9711d471d193 Reviewed-by: Oliver Wolff --- src/plugins/sensors/winrt/main.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/plugins') diff --git a/src/plugins/sensors/winrt/main.cpp b/src/plugins/sensors/winrt/main.cpp index e66e0ade..2b868e2f 100644 --- a/src/plugins/sensors/winrt/main.cpp +++ b/src/plugins/sensors/winrt/main.cpp @@ -52,6 +52,7 @@ #include #include #include +#include class WinRtSensorPlugin : public QObject, public QSensorPluginInterface, public QSensorBackendFactory { @@ -60,8 +61,17 @@ class WinRtSensorPlugin : public QObject, public QSensorPluginInterface, public Q_INTERFACES(QSensorPluginInterface) public: + ~WinRtSensorPlugin() + { + CoUninitialize(); + } + void registerSensors() override { + if (FAILED(CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED))) { + qErrnoWarning("CoInitializeEx() failed."); + return; + } QSensorManager::registerBackend(QAccelerometer::sensorType, QByteArrayLiteral("WinRtAccelerometer"), this); QSensorManager::registerBackend(QCompass::sensorType, QByteArrayLiteral("WinRtCompass"), this); QSensorManager::registerBackend(QGyroscope::sensorType, QByteArrayLiteral("WinRtGyroscope"), this); -- cgit v1.2.3