I'm trying to use the ProximitySensor
in QML. I didn't find examples of how to use it. I'm using QtSensors 5.0. I tried get if something is near by calling the reading
property, but this property only have this properties: deleteLater
, objectName
and timestamp
. I tried this ProximityReading.near
, but it returns undefined. I also tried this proximitySensor.close()
, but it returns that proximitySensor was not defined. The proximity sensor is working fine, because I tested in my smartphone the property reading.timestamp
and the values was updated properly.
My code is something like this:
import QtSensors 5.0
ProximitySensor {
id: proximity
active: true
dataRate: 100
onReadingChanged: {
// How do I get if something is near?
}
onErrorChanged: {
}
}
The type info may not be property interfaced to be read by Creator, but the properties and methods should be there nonetheless. Try this:
onReadingChanged: {
if (reading.near) console.log("it is near")
else console.log("it is far")
}