이 페이지에서

QSensorReading Class

QSensorReading 클래스는 센서에서 읽어온 측정값을 저장합니다. 더 보기...

헤더: #include <QSensorReading>
CMake: find_package(Qt6 REQUIRED COMPONENTS Sensors)
target_link_libraries(mytarget PRIVATE Qt6::Sensors)
qmake: QT += sensors
상속: QObject
상속받는 클래스:
13가지 유형

QAccelerometerReading, QAmbientLightReading, QAmbientTemperatureReading, QCompassReading, QGyroscopeReading, QHumidityReading, QLightReading, QMagnetometerReading, QOrientationReading, QPressureReading, QProximityReading, QRotationReading 및 QTiltReading

속성

공개 함수

void setTimestamp(quint64 timestamp)
quint64 timestamp() const
QVariant value(int index) const
int valueCount() const

매크로

DECLARE_READING(classname)
IMPLEMENT_READING(classname)

상세 설명

QSensorReading 자체만으로는 별다른 유용성이 없다는 점에 유의하십시오. 각 센서에 대한 유용한 데이터는 QSensorReading의 하위 클래스에서 정의됩니다.

속성 설명

[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()를 호출해야 합니다.

qreal x = reading->property("x").value<qreal>();

마지막으로, 숫자 인덱스를 통해 값에 접근할 수도 있습니다.

qreal x = reading->value(0).value<qreal>();

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.