Dice: Ignore accelerometer reading until it's ready

The documentation for reading refers to QSensor::reading and it states
that readings are not available immediately after start() is called.
Instead, one should wait for the readingChanged signal. Until then,
reading is documented to be null, so just check for that.

This fixes 'Cannot read property x of null' warnings.

Fixes: QTBUG-140395
Fixes: QTBUG-140385
Pick-to: 6.10
Change-Id: Ibb36e1d8387628eea333cb6d0537dea25f3980b6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
This commit is contained in:
Olivier De Cannière 2025-09-23 11:07:47 +02:00
parent ad14f02eb2
commit d19a1e9b51
1 changed files with 2 additions and 0 deletions

View File

@ -19,6 +19,8 @@ ApplicationWindow {
dataRate: 25 dataRate: 25
active: true active: true
readonly property vector3d force: { readonly property vector3d force: {
if (!reading)
return Qt.vector3d(0, 0, 0)
let r = reading as AccelerometerReading let r = reading as AccelerometerReading
return Qt.vector3d(r.x, r.y, r.z) return Qt.vector3d(r.x, r.y, r.z)
} }