From 5a8aa096dc61336ac95734e8cc61f106e359c865 Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Tue, 5 Jan 2021 14:27:16 +0200 Subject: Base commit to make QtSensors runnable on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fair amount of work remains after the commit still, but this should allow further development as a compilable baseline: code compiles, autotests pass, and most example applications at least start. The changes: -Change examples to use QtQuickControls 2 as per removal of v1 -Fix ambiguous conditional expression compilation error -Link against runtimeobject library (previously part of winrt QPA?) -Change the .pro file rule to win32 as winrt moniker does not exist anymore -Remove references to deleted winrt event dispatcher -Fix error handling: getdefault may be successful even if there is no default sensor -Fix QCOMPARE failure output (toString has changed in Qt6) -Remove qtimestamp alias which was deprecated already in Qt5 -Remove unit test hook that does not seem to be used anywhere -From typedef to ‘using’ for readability -Q_ENUMS -> Q_ENUM as the former has been obsoleted by the latter -Add qt6 changes qdoc page Task-number: QTBUG-88616 Change-Id: I92c168228ba76106b2c636c88f54331c76c3d2e6 Reviewed-by: Karsten Heimrich Reviewed-by: Oliver Wolff Reviewed-by: Alex Blasche --- src/plugins/sensors/generic/generictiltsensor.cpp | 2 +- src/plugins/sensors/sensors.pro | 4 +- src/plugins/sensors/winrt/main.cpp | 1 + src/plugins/sensors/winrt/winrt.pro | 2 + src/plugins/sensors/winrt/winrtaccelerometer.cpp | 47 +++++++++++----------- .../sensors/winrt/winrtambientlightsensor.cpp | 44 +++++++++----------- src/plugins/sensors/winrt/winrtcompass.cpp | 46 ++++++++++----------- src/plugins/sensors/winrt/winrtgyroscope.cpp | 44 ++++++++++---------- src/plugins/sensors/winrt/winrtgyroscope.h | 2 +- .../sensors/winrt/winrtorientationsensor.cpp | 43 +++++++++----------- src/plugins/sensors/winrt/winrtrotationsensor.cpp | 45 ++++++++++----------- src/plugins/sensors/winrt/winrtrotationsensor.h | 2 +- 12 files changed, 134 insertions(+), 148 deletions(-) (limited to 'src/plugins/sensors') diff --git a/src/plugins/sensors/generic/generictiltsensor.cpp b/src/plugins/sensors/generic/generictiltsensor.cpp index bb418893..ddb6bde3 100644 --- a/src/plugins/sensors/generic/generictiltsensor.cpp +++ b/src/plugins/sensors/generic/generictiltsensor.cpp @@ -161,5 +161,5 @@ bool GenericTiltSensor::filter(QAccelerometerReading *reading) bool GenericTiltSensor::isFeatureSupported(QSensor::Feature feature) const { - return (feature == QSensor::SkipDuplicates); + return (feature == QSensor::Feature::SkipDuplicates); } diff --git a/src/plugins/sensors/sensors.pro b/src/plugins/sensors/sensors.pro index 7fce2071..c637e6ac 100644 --- a/src/plugins/sensors/sensors.pro +++ b/src/plugins/sensors/sensors.pro @@ -13,7 +13,7 @@ darwin { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = ios generic } -winrt { +win32 { isEmpty(SENSORS_PLUGINS): SENSORS_PLUGINS = winrt generic } @@ -42,4 +42,4 @@ isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, android):android:SUBDIRS += a isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensorfw):sensorfw:SUBDIRS += sensorfw isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, sensortag):linux:SUBDIRS += sensortag isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, ios):darwin:SUBDIRS += ios -isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):winrt:SUBDIRS += winrt +isEmpty(SENSORS_PLUGINS)|contains(SENSORS_PLUGINS, winrt):SUBDIRS += winrt diff --git a/src/plugins/sensors/winrt/main.cpp b/src/plugins/sensors/winrt/main.cpp index ecf2a41b..cae34037 100644 --- a/src/plugins/sensors/winrt/main.cpp +++ b/src/plugins/sensors/winrt/main.cpp @@ -59,6 +59,7 @@ class WinRtSensorPlugin : public QObject, public QSensorPluginInterface, public Q_PLUGIN_METADATA(IID "com.qt-project.Qt.QSensorPluginInterface/1.0" FILE "plugin.json") Q_INTERFACES(QSensorPluginInterface) public: + void registerSensors() override { QSensorManager::registerBackend(QAccelerometer::type, QByteArrayLiteral("WinRtAccelerometer"), this); diff --git a/src/plugins/sensors/winrt/winrt.pro b/src/plugins/sensors/winrt/winrt.pro index 21996fdd..0de6293b 100644 --- a/src/plugins/sensors/winrt/winrt.pro +++ b/src/plugins/sensors/winrt/winrt.pro @@ -22,6 +22,8 @@ SOURCES += \ OTHER_FILES = plugin.json +LIBS += runtimeobject.lib + PLUGIN_TYPE = sensors PLUGIN_CLASS_NAME = WinRtSensorPlugin load(qt_plugin) diff --git a/src/plugins/sensors/winrt/winrtaccelerometer.cpp b/src/plugins/sensors/winrt/winrtaccelerometer.cpp index 3570a47d..e2bc0613 100644 --- a/src/plugins/sensors/winrt/winrtaccelerometer.cpp +++ b/src/plugins/sensors/winrt/winrtaccelerometer.cpp @@ -41,11 +41,11 @@ #include "winrtcommon.h" #include -#include #include #include #include + using namespace Microsoft::WRL; using namespace Microsoft::WRL::Wrappers; using namespace ABI::Windows::Foundation; @@ -119,28 +119,30 @@ WinRtAccelerometer::WinRtAccelerometer(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtAccelerometerPrivate(this)) { Q_D(WinRtAccelerometer); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Accelerometer); - ComPtr factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize accelerometer factory." + + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Accelerometer); + ComPtr factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize accelerometer factory." << qt_error_string(hr); - return hr; - } + sensorError(hr); + return; + } + hr = factory->GetDefault(&d->sensor); - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default accelerometer." + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default accelerometer." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default accelerometer was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -167,11 +169,10 @@ void WinRtAccelerometer::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr callback = - Callback(d, &WinRtAccelerometerPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + ComPtr callback = + Callback(d, &WinRtAccelerometerPrivate::readingChanged); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -200,9 +201,7 @@ void WinRtAccelerometer::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtambientlightsensor.cpp b/src/plugins/sensors/winrt/winrtambientlightsensor.cpp index 426d61bf..7832eb1c 100644 --- a/src/plugins/sensors/winrt/winrtambientlightsensor.cpp +++ b/src/plugins/sensors/winrt/winrtambientlightsensor.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include -#include #include #include @@ -118,27 +117,27 @@ WinRtAmbientLightSensor::WinRtAmbientLightSensor(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtAmbientLightSensorPrivate(this)) { Q_D(WinRtAmbientLightSensor); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_LightSensor); - ComPtr factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." - << qt_error_string(hr); - return hr; - } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default light sensor." + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_LightSensor); + ComPtr factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default light sensor." + << qt_error_string(hr); + sensorError(hr); + return; + } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default lightsensor was not found on the system."; + return; + } hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { @@ -166,11 +165,10 @@ void WinRtAmbientLightSensor::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr callback = + ComPtr callback = Callback(d, &WinRtAmbientLightSensorPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -199,9 +197,7 @@ void WinRtAmbientLightSensor::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtcompass.cpp b/src/plugins/sensors/winrt/winrtcompass.cpp index 5ef730d0..bfe70d77 100644 --- a/src/plugins/sensors/winrt/winrtcompass.cpp +++ b/src/plugins/sensors/winrt/winrtcompass.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include -#include #include #include @@ -136,28 +135,30 @@ WinRtCompass::WinRtCompass(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtCompassPrivate(this)) { Q_D(WinRtCompass); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Compass); - ComPtr factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." + + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Compass); + ComPtr factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize light sensor factory." << qt_error_string(hr); - return hr; - } + sensorError(hr); + return; + } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default compass." + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default compass." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default compass was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -183,12 +184,10 @@ void WinRtCompass::start() return; if (d->token.value) return; - - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr callback = + ComPtr callback = Callback(d, &WinRtCompassPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -216,9 +215,8 @@ void WinRtCompass::stop() return; if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtgyroscope.cpp b/src/plugins/sensors/winrt/winrtgyroscope.cpp index 45b544c7..3de73247 100644 --- a/src/plugins/sensors/winrt/winrtgyroscope.cpp +++ b/src/plugins/sensors/winrt/winrtgyroscope.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include -#include #include #include @@ -116,28 +115,30 @@ WinRtGyroscope::WinRtGyroscope(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtGyroscopePrivate(this)) { Q_D(WinRtGyroscope); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer); - ComPtr factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory." + + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Gyrometer); + ComPtr factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize gyroscope sensor factory." << qt_error_string(hr); - return hr; - } + sensorError(hr); + return; + } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor." + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default gyroscope sensor." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default gyroscope was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -164,11 +165,10 @@ void WinRtGyroscope::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr callback = + ComPtr callback = Callback(d, &WinRtGyroscopePrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -197,9 +197,7 @@ void WinRtGyroscope::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtgyroscope.h b/src/plugins/sensors/winrt/winrtgyroscope.h index 7bd85332..308b769e 100644 --- a/src/plugins/sensors/winrt/winrtgyroscope.h +++ b/src/plugins/sensors/winrt/winrtgyroscope.h @@ -55,7 +55,7 @@ public: bool isFeatureSupported(QSensor::Feature feature) const override { - if (feature == QSensor::AxesOrientation || feature == QSensor::AccelerationMode) + if (feature == QSensor::Feature::AxesOrientation || feature == QSensor::Feature::AccelerationMode) return true; return false; } diff --git a/src/plugins/sensors/winrt/winrtorientationsensor.cpp b/src/plugins/sensors/winrt/winrtorientationsensor.cpp index e24ff954..1511a308 100644 --- a/src/plugins/sensors/winrt/winrtorientationsensor.cpp +++ b/src/plugins/sensors/winrt/winrtorientationsensor.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include -#include #include #include @@ -122,27 +121,26 @@ WinRtOrientationSensor::WinRtOrientationSensor(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtOrientationSensorPrivate(this)) { Q_D(WinRtOrientationSensor); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_SimpleOrientationSensor); - ComPtr factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize orientation sensor factory." + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_SimpleOrientationSensor); + ComPtr factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize orientation sensor factory." << qt_error_string(hr); - return hr; - } - - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default orientation sensor." + sensorError(hr); + return; + } + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default orientation sensor." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default orientationsensor was not found on the system."; + return; + } setReading(&d->reading); } @@ -159,11 +157,10 @@ void WinRtOrientationSensor::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr callback = + ComPtr callback = Callback(d, &WinRtOrientationSensorPrivate::readingChanged); - return d->sensor->add_OrientationChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_OrientationChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -180,9 +177,7 @@ void WinRtOrientationSensor::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_OrientationChanged(d->token); - }); + HRESULT hr = d->sensor->remove_OrientationChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtrotationsensor.cpp b/src/plugins/sensors/winrt/winrtrotationsensor.cpp index 5dd4eae5..4f37ea15 100644 --- a/src/plugins/sensors/winrt/winrtrotationsensor.cpp +++ b/src/plugins/sensors/winrt/winrtrotationsensor.cpp @@ -41,7 +41,6 @@ #include "winrtcommon.h" #include -#include #include #include @@ -114,28 +113,29 @@ WinRtRotationSensor::WinRtRotationSensor(QSensor *sensor) : QSensorBackend(sensor), d_ptr(new WinRtRotationSensorPrivate(this)) { Q_D(WinRtRotationSensor); - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Inclinometer); - ComPtr factory; - HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to initialize rotation sensor factory." - << qt_error_string(hr); - return hr; - } - hr = factory->GetDefault(&d->sensor); - if (FAILED(hr)) { - qCWarning(lcWinRtSensors) << "Unable to get default rotation sensor." + HStringReference classId(RuntimeClass_Windows_Devices_Sensors_Inclinometer); + ComPtr factory; + HRESULT hr = RoGetActivationFactory(classId.Get(), IID_PPV_ARGS(&factory)); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to initialize rotation sensor factory." + << qt_error_string(hr); + sensorError(hr); + return; + } + hr = factory->GetDefault(&d->sensor); + if (FAILED(hr)) { + qCWarning(lcWinRtSensors) << "Unable to get default rotation sensor." << qt_error_string(hr); - } - return hr; - }); - if (FAILED(hr) || !d->sensor) { sensorError(hr); return; } + if (!d->sensor) { + qCWarning(lcWinRtSensors) << "Default rotationsensor was not found on the system."; + return; + } + hr = d->sensor->get_MinimumReportInterval(&d->minimumReportInterval); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to get the minimum report interval." @@ -162,11 +162,10 @@ void WinRtRotationSensor::start() if (d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - ComPtr callback = + ComPtr callback = Callback(d, &WinRtRotationSensorPrivate::readingChanged); - return d->sensor->add_ReadingChanged(callback.Get(), &d->token); - }); + HRESULT hr = d->sensor->add_ReadingChanged(callback.Get(), &d->token); + if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to attach to reading changed event." << qt_error_string(hr); @@ -195,9 +194,7 @@ void WinRtRotationSensor::stop() if (!d->token.value) return; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - return d->sensor->remove_ReadingChanged(d->token); - }); + HRESULT hr = d->sensor->remove_ReadingChanged(d->token); if (FAILED(hr)) { qCWarning(lcWinRtSensors) << "Unable to detach from reading changed event." << qt_error_string(hr); diff --git a/src/plugins/sensors/winrt/winrtrotationsensor.h b/src/plugins/sensors/winrt/winrtrotationsensor.h index 4b3e6faf..39fa4551 100644 --- a/src/plugins/sensors/winrt/winrtrotationsensor.h +++ b/src/plugins/sensors/winrt/winrtrotationsensor.h @@ -55,7 +55,7 @@ public: bool isFeatureSupported(QSensor::Feature feature) const override { - if (feature == QSensor::AxesOrientation || feature == QSensor::AccelerationMode) + if (feature == QSensor::Feature::AxesOrientation || feature == QSensor::Feature::AccelerationMode) return true; return false; } -- cgit v1.2.3