简体   繁体   English

如何在QML中使用android的接近传感器来获取信息

[英]How do I get if something is near using proximity sensor in android with QML

I'm trying to use the ProximitySensor in QML. 我正在尝试在QML中使用ProximitySensor I didn't find examples of how to use it. 我没有找到如何使用它的示例。 I'm using QtSensors 5.0. 我正在使用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 . 我试图得到,如果事情是附近通过调用reading属性,但此属性唯一有此属性: deleteLaterobjectNametimestamp I tried this ProximityReading.near , but it returns undefined. 我尝试了这个ProximityReading.near ,但是它返回未定义的。 I also tried this proximitySensor.close() , but it returns that proximitySensor was not defined. 我也试过了这个proximitySensor.close() ,但是它返回未定义接近传感器。 The proximity sensor is working fine, because I tested in my smartphone the property reading.timestamp and the values was updated properly. 接近传感器工作正常,因为我在智能手机中测试了属性reading.timestamp ,并且值已正确更新。

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. 类型信息可能不是由Creator读取的属性接口,但是属性和方法仍然应该存在。 Try this: 尝试这个:

onReadingChanged: {
     if (reading.near) console.log("it is near")
     else console.log("it is far")
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM