本页内容

QMagnetometerReading Class

QMagnetometerReading 类表示磁力计的单次读数。更多内容...

头文件: #include <QMagnetometerReading>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sensors)
target_link_libraries(mytarget PRIVATE Qt6::Sensors)
qmake: QT += sensors
继承自: QSensorReading

属性

公共函数

qreal calibrationLevel() const
void setCalibrationLevel(qreal calibrationLevel)
void setX(qreal x)
void setY(qreal y)
void setZ(qreal z)
qreal x() const
qreal y() const
qreal z() const

详细说明

QMagnetometerReading Units

磁力计返回沿3个轴方向的磁通密度值。这些值的单位为特斯拉。各轴的排列如下。

一种具有正负x、y和z轴且这三轴向六个方向延伸的装置

磁力计可报告原始磁通量值或地磁通量值。默认情况下,它返回原始磁通量值。若要返回地磁通量值,必须将QMagnetometer::returnGeoValues 属性设置为相应值。

原始值与地磁值的主要区别在于,地磁值经过额外处理以消除局部磁干扰,从而仅反映地球磁场的影响。此过程并非完美无缺,每次读数的精度可能会有所变化。

下图展示了在受到磁干扰的情况下,某款手机的地磁读数(左侧)与原始读数(右侧)之间的差异。

一张对比图,展示了地磁读数(手机坐标轴对准磁北极)与受附近磁铁影响而产生偏移的原始读数

每次读数的准确度以0到1之间的数值表示。数值1代表设备所能支持的最高水平,0则代表最差水平。

校准

如果设备报告的精度较低,则可能需要进行校准,才能获得可接受的测量结果。基本校准通常可通过让设备沿“8”字形旋转,或沿其三个轴分别旋转来完成。有关更多信息,请查阅设备文档中关于如何校准磁传感器的说明。

属性文档

[read-only] calibrationLevel : qreal

该属性表示读数的精度。

测量值为0到1之间的数值,数值越高越好。

请注意,该属性仅在测量地磁通量密度时才会发生变化。原始磁通量读数始终为1。

访问函数:

qreal calibrationLevel() const

另请参阅 QMagnetometerReading Units 和Calibration 。

[read-only] x : qreal

该属性表示X轴上的原始磁通密度。

单位为特斯拉。

访问函数:

qreal x() const

另请参阅 QMagnetometerReading Units 。

[read-only] y : qreal

该属性在 Y 轴上存储原始磁通密度。

单位为特斯拉。

访问函数:

qreal y() const

另请参阅 QMagnetometerReading Units 。

[read-only] z : qreal

该属性存储 Z 轴上的原始磁通密度。

单位为特斯拉。

访问函数:

qreal z() const

另请参阅 QMagnetometerReading Units 。

成员函数文档

void QMagnetometerReading::setCalibrationLevel(qreal calibrationLevel)

将读数精度设置为calibrationLevel 。

另请参阅 calibrationLevel()。

void QMagnetometerReading::setX(qreal x)

将X轴上的原始磁通密度设置为x 。

另请参阅 x()。

void QMagnetometerReading::setY(qreal y)

将Y轴上的原始磁通密度设置为y 。

另请参阅 y()。

void QMagnetometerReading::setZ(qreal z)

将 Z 轴上的原始磁通密度设置为z 。

另请参阅 z()。

© 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.