0

我正在尝试ProximitySensor在 QML 中使用。我没有找到如何使用它的示例。我正在使用 QtSensors 5.0。我尝试通过调用该属性来获取附近是否有东西reading,但该属性只有以下属性deleteLaterobjectNametimestamp。我试过这个ProximityReading.near,但它返回未定义。我也试过这个proximitySensor.close(),但它返回未定义proximitySensor。接近传感器工作正常,因为我在智能手机中测试了属性reading.timestamp并且值已正确更新。

我的代码是这样的:

import  QtSensors 5.0
ProximitySensor {
    id: proximity
    active: true
    dataRate: 100

    onReadingChanged: {
        // How do I get if something is near?

    }

    onErrorChanged: {

    }
}
4

1 回答 1

1

类型信息可能不是由 Creator 读取的属性接口,但属性和方法应该在那里。试试这个:

onReadingChanged: {
     if (reading.near) console.log("it is near")
     else console.log("it is far")
}
于 2018-02-18T18:27:03.377 回答