QSensorReading Class
QSensorReading 类用于存储来自传感器的读数。更多内容...
| 头文件: | #include <QSensorReading> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Sensors) target_link_libraries(mytarget PRIVATE Qt6::Sensors) |
| qmake: | QT += sensors |
| 继承自: | QObject |
| 继承自: |
属性
- timestamp : quint64
公共函数
| void | setTimestamp(quint64 timestamp) |
| quint64 | timestamp() const |
| QVariant | value(int index) const |
| int | valueCount() const |
宏
| DECLARE_READING(classname) | |
| IMPLEMENT_READING(classname) |
属性文档
[read-only] timestamp : quint64
该属性存储了读数的时间戳。
时间戳的值是以某个固定点为基准的微秒数。您可以利用时间戳来判断两个传感器读数之间的间隔有多大。
请注意,来自不同传感器的读数时间戳可能无法直接比较(因为它们可能选择不同的基准点作为参考)。
请注意,某些平台无法正确提供时间戳。应用程序应做好准备,应对偶尔导致时间戳倒跳的问题。
访问函数:
| quint64 | timestamp() const |
成员函数文档
void QSensorReading::setTimestamp(quint64 timestamp)
设置读取操作的timestamp 。
另请参阅 timestamp()。
quint64 QSensorReading::timestamp() const
返回读取操作的时间戳。
注意: 这是 timestamp 属性的获取 函数。
另请参阅 setTimestamp()。
QVariant QSensorReading::value(int index) const
返回index 处该属性的值。
请注意,此函数的运行速度比直接调用 data 函数要慢。
以下是一个通过不同机制获取属性的示例。
直接访问性能最佳,但需要在编译时就了解要访问的数据。
QAccelerometerReading *reading = ...;
qreal x = reading->x();您也可以按名称访问属性。要做到这一点,必须调用QObject::property()。
最后,您可以通过数字索引访问值。
请注意,value() 只能访问在QSensorReading 的子类中使用Q_PROPERTY() 声明的属性。
另请参阅 ` valueCount()` 和 `QObject::property()`。
int QSensorReading::valueCount() const
返回该读取结果中包含的额外属性数量。
请注意,这不包括在QSensorReading 中声明的属性。
例如,对于QAccelerometerReading ,该方法返回 3,因为该类中定义了 3 个属性。
宏文档
DECLARE_READING(classname)
DECLARE_READING 宏会向读取类添加一些必需的方法。
应将此宏应用于所有读取类。请传入您的读取类的classname 。
class MyReadingPrivate;
class MyReading : public QSensorReading
{
Q_OBJECT
Q_PROPERTY(qreal myprop READ myprop)
DECLARE_READING(MyReading)
public:
qreal myprop() const;
void setMyprop(qreal myprop);
};另请参阅 IMPLEMENT_READING()。
IMPLEMENT_READING(classname)
IMPLEMENT_READING 宏实现了读取类所需的方法。
所有读取类都应使用此宏。该宏应放置在一个单独的编译单元(源文件)中,而非头文件中。请传入您的读取类的classname 。
IMPLEMENT_READING(MyReading)另请参阅 DECLARE_READING()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.