内容表

上一话题

QRotationSensor

下一话题

QSensorBackend

QSensor

QSensor class represents a single hardware sensor. 更多

Inheritance diagram of PySide2.QtSensors.QSensor

继承者: QAccelerometer , QAltimeter , QAmbientLightSensor , QAmbientTemperatureSensor , QCompass , QDistanceSensor , QGyroscope , QHolsterSensor , QHumiditySensor , QIRProximitySensor , QLidSensor , QLightSensor , QMagnetometer , QOrientationSensor , QPressureSensor , QProximitySensor , QRotationSensor , QTapSensor , QTiltSensor

概要

函数

信号

静态函数

详细描述

通常,传感器的生命周期为:

  • Create a sub-class of QSensor on the stack or heap.

  • 通过应用程序按要求设置。

  • 开始接收值。

  • 通过应用程序使用传感器数据。

  • 停止接收值。

交付传感器数据凭借 QSensorReading 及其子类。

取向

Some sensors react to screen orientation changes, such as QAccelerometer , QMagnetometer and QRotationSensor . These are so called orientable sensors. For orientable sensors, QSensor supports changing the reporting of the reading values based on the orientation of the screen.

For orientable sensors, the axesOrientationMode property controls how the orientation affects the reading values.

In the default mode, FixedOrientation , the reading values remain unaffected by the orientation. In the AutomaticOrientation mode, the reading values are automatically rotated by taking the current screen orientation into account. And finally, in the UserOrientation mode, the reading values are rotated according to a user-specified orientation.

The functionality of this is only available if it is supported by the backend and if the sensor is orientable, which can be checked by calling isFeatureSupported() 采用 AxesOrientation 标志。

The orientation values here are always of the screen orientation, not the device orientation. The screen orientation is the orientation of the GUI. For example when rotating a device by 90 degrees counter-clockwise, the screen orientation compensates for that by rotating 90 degrees clockwise, to the effect that the GUI is still facing upright after the device has been rotated. Note that applications can lock the screen orientation, for example to force portrait or landscape mode. For locked orientations, orientable sensors will not react with reading changes if the device orientation is changed, as orientable sensors react to screen orientation changes only. This makes sense, as the purpose of orientable sensors is to keep the sensor orientation in sync with the screen orientation.

The orientation values range from 0 to 270 degrees. The orientation is applied in clockwise direction, e.g. an orientation value of 90 degrees means that the screen has been rotated 90 degress to the right from its origin position, to compensate a device rotation of 90 degrees to the left.

另请参阅

QSensorReading

class QSensor ( type [ , parent=Q_NULLPTR ] )
param type

QByteArray

param parent

QObject

Construct the type sensor as a child of parent .

Do not use this constructor if a derived class exists for the specific sensor type.

The wrong way is to use the base class constructor:

QSensor *magnetometer = new QSensor(QMagnetometer::type, this);
												

The right way is to create an instance of the derived class:

QMagnetometer *magnetometer = new QMagnetometer(this);
												

The derived classes have additional properties and data members which are needed for certain features such as geo value support in QMagnetometer or acceleration mode support in QAccelerometer . These features will only work properly when creating a sensor instance from a QSensor 子类。

Only use this constructor if there is no derived sensor class available. Note that all built-in sensors have a derived class, so using this constructor should only be necessary when implementing custom sensors, like in the Grue sensor example .

PySide2.QtSensors.QSensor. Feature

Lists optional features a backend might support.

The features common to all sensor types are:

常量

描述

QSensor.Buffering

The backend supports buffering of readings, controlled by the bufferSize 特性。

QSensor.AlwaysOn

The backend supports changing the policy on whether to suspend when idle, controlled by the alwaysOn 特性。

QSensor.SkipDuplicates

The backend supports skipping of same or very similar successive readings. This can be enabled by setting the skipDuplicates property to true.

The features of QMagnetometer 是:

常量

描述

QSensor.GeoValues

The backend supports returning geo values, which can be controlled with the returnGeoValues 特性。

The features of QLightSensor 是:

常量

描述

QSensor.FieldOfView

The backend specifies its field of view, which can be read from the fieldOfView 特性。

The features of QAccelerometer 是:

常量

描述

QSensor.AccelerationMode

The backend supports switching the acceleration mode of the acceleromter with the accelerationMode 特性。

The features of QPressureSensor 是:

常量

描述

QSensor.PressureSensorTemperature

The backend provides the pressure sensor’s die temperature

所有可定向传感器特征:

常量

描述

QSensor.AxesOrientation

The backend supports changing the axes orientation from the default of FixedOrientation to something else.

PySide2.QtSensors.QSensor. AxesOrientationMode

Describes how reading values are affected by the screen orientation.

常量

描述

QSensor.FixedOrientation

No automatic rotation is applied to the reading values.

QSensor.AutomaticOrientation

The reading values are automatically rotated based on the screen orientation.

QSensor.UserOrientation

The reading values are rotated based on the angle of the userOrientation 特性。

PySide2.QtSensors.QSensor. activeChanged ( )
PySide2.QtSensors.QSensor. addFilter ( filter )
参数

filter QSensorFilter

Add a filter to the sensor.

The sensor does not take ownership of the filter. QSensorFilter will inform the sensor if it is destroyed.

另请参阅

QSensorFilter

PySide2.QtSensors.QSensor. alwaysOnChanged ( )
PySide2.QtSensors.QSensor. availableDataRates ( )
返回类型

PySide2.QtSensors.QSensor. availableSensorsChanged ( )
PySide2.QtSensors.QSensor. axesOrientationMode ( )
返回类型

AxesOrientationMode

PySide2.QtSensors.QSensor. axesOrientationModeChanged ( axesOrientationMode )
参数

axesOrientationMode AxesOrientationMode

PySide2.QtSensors.QSensor. backend ( )
返回类型

QSensorBackend

PySide2.QtSensors.QSensor. bufferSize ( )
返回类型

int

另请参阅

setBufferSize()

PySide2.QtSensors.QSensor. bufferSizeChanged ( bufferSize )
参数

bufferSize int

PySide2.QtSensors.QSensor. busyChanged ( )
PySide2.QtSensors.QSensor. connectToBackend ( )
返回类型

bool

Try to connect to a sensor backend.

Returns true if a suitable backend could be found, false otherwise.

The type must be set before calling this method if you are using QSensor directly.

PySide2.QtSensors.QSensor. currentOrientation ( )
返回类型

int

PySide2.QtSensors.QSensor. currentOrientationChanged ( currentOrientation )
参数

currentOrientation int

PySide2.QtSensors.QSensor. dataRate ( )
返回类型

int

另请参阅

setDataRate()

PySide2.QtSensors.QSensor. dataRateChanged ( )
static PySide2.QtSensors.QSensor. defaultSensorForType ( type )
参数

type QByteArray

返回类型

QByteArray

Returns the default sensor identifier for type . This is set in a config file and can be overridden if required. If no default is available the system will return the first registered sensor for type .

Note that there is special case logic to prevent the generic plugin’s backends from becoming the default when another backend is registered for the same type. This logic means that a backend identifier starting with generic. will only be the default if no other backends have been registered for that type or if it is specified in Sensors.conf .

PySide2.QtSensors.QSensor. description ( )
返回类型

unicode

PySide2.QtSensors.QSensor. efficientBufferSize ( )
返回类型

int

PySide2.QtSensors.QSensor. efficientBufferSizeChanged ( efficientBufferSize )
参数

efficientBufferSize int

PySide2.QtSensors.QSensor. error ( )
返回类型

int

PySide2.QtSensors.QSensor. filters ( )
返回类型

Returns the filters currently attached to the sensor.

另请参阅

QSensorFilter

PySide2.QtSensors.QSensor. identifier ( )
返回类型

QByteArray

另请参阅

setIdentifier()

PySide2.QtSensors.QSensor. isActive ( )
返回类型

bool

PySide2.QtSensors.QSensor. isAlwaysOn ( )
返回类型

bool

PySide2.QtSensors.QSensor. isBusy ( )
返回类型

bool

PySide2.QtSensors.QSensor. isConnectedToBackend ( )
返回类型

bool

PySide2.QtSensors.QSensor. isFeatureSupported ( feature )
参数

feature Feature

返回类型

bool

Checks if a specific feature is supported by the backend.

QtSensors supports a rich API for controlling and providing information about sensors. Naturally, not all of this functionality can be supported by all of the backends.

To check if the current backend supports the feature feature , call this function.

The backend needs to be connected, otherwise false will be returned. Calling connectToBackend() or start() will create a connection to the backend.

Backends have to implement isFeatureSupported() to make this work.

Returns whether or not the feature is supported if the backend is connected, or false if the backend is not connected.

PySide2.QtSensors.QSensor. maxBufferSize ( )
返回类型

int

PySide2.QtSensors.QSensor. maxBufferSizeChanged ( maxBufferSize )
参数

maxBufferSize int

PySide2.QtSensors.QSensor. outputRange ( )
返回类型

int

另请参阅

setOutputRange()

PySide2.QtSensors.QSensor. outputRanges ( )
返回类型

PySide2.QtSensors.QSensor. reading ( )
返回类型

QSensorReading

PySide2.QtSensors.QSensor. readingChanged ( )
PySide2.QtSensors.QSensor. removeFilter ( filter )
参数

filter QSensorFilter

移除 filter from the sensor.

另请参阅

QSensorFilter

PySide2.QtSensors.QSensor. sensorError ( error )
参数

error int

static PySide2.QtSensors.QSensor. sensorTypes ( )
返回类型

Returns a list of all sensor types.

static PySide2.QtSensors.QSensor. sensorsForType ( type )
参数

type QByteArray

返回类型

Returns a list of ids for each of the sensors for type . If there are no sensors of that type available the list will be empty.

PySide2.QtSensors.QSensor. setActive ( active )
参数

active bool

另请参阅

isActive()

PySide2.QtSensors.QSensor. setAlwaysOn ( alwaysOn )
参数

alwaysOn bool

另请参阅

isAlwaysOn()

PySide2.QtSensors.QSensor. setAxesOrientationMode ( axesOrientationMode )
参数

axesOrientationMode AxesOrientationMode

PySide2.QtSensors.QSensor. setBufferSize ( bufferSize )
参数

bufferSize int

另请参阅

bufferSize()

PySide2.QtSensors.QSensor. setCurrentOrientation ( currentOrientation )
参数

currentOrientation int

Sets the current screen orientation to currentOrientation . This is to be called from the backend whenever the screen orientation or the userOrientation 特性改变。

PySide2.QtSensors.QSensor. setDataRate ( rate )
参数

rate int

另请参阅

dataRate()

PySide2.QtSensors.QSensor. setEfficientBufferSize ( efficientBufferSize )
参数

efficientBufferSize int

Sets the efficient buffer size to efficientBufferSize . This is to be called from the backend.

PySide2.QtSensors.QSensor. setIdentifier ( identifier )
参数

identifier QByteArray

另请参阅

identifier()

PySide2.QtSensors.QSensor. setMaxBufferSize ( maxBufferSize )
参数

maxBufferSize int

Sets the maximum buffer size to maxBufferSize . This is to be called from the backend.

另请参阅

maxBufferSize()

PySide2.QtSensors.QSensor. setOutputRange ( index )
参数

index int

另请参阅

outputRange()

PySide2.QtSensors.QSensor. setSkipDuplicates ( skipDuplicates )
参数

skipDuplicates bool

Sets the duplicate skipping to skipDuplicates .

另请参阅

skipDuplicates()

PySide2.QtSensors.QSensor. setUserOrientation ( userOrientation )
参数

userOrientation int

另请参阅

userOrientation()

PySide2.QtSensors.QSensor. skipDuplicates ( )
返回类型

bool

PySide2.QtSensors.QSensor. skipDuplicatesChanged ( skipDuplicates )
参数

skipDuplicates bool

PySide2.QtSensors.QSensor. start ( )
返回类型

bool

Start retrieving values from the sensor. Returns true if the sensor was started, false otherwise.

The sensor may fail to start for several reasons.

Once an application has started a sensor it must wait until the sensor receives a new value before it can query the sensor’s values. This is due to how the sensor receives values from the system. Sensors do not (in general) poll for new values, rather new values are pushed to the sensors as they happen.

For example, this code will not work as intended.

sensor->start();
sensor->reading()->x(); // no data available
												

To work correctly, the code that accesses the reading should ensure the readingChanged() 信号已被发射。

    connect(sensor, SIGNAL(readingChanged()), this, SLOT(checkReading()));
    sensor->start();
}
void MyClass::checkReading() {
    sensor->reading()->x();
												

另请参阅

busy

PySide2.QtSensors.QSensor. stop ( )

Stop retrieving values from the sensor.

This releases the sensor so that other processes can use it.

另请参阅

busy

PySide2.QtSensors.QSensor. type ( )
返回类型

QByteArray

PySide2.QtSensors.QSensor. userOrientation ( )
返回类型

int

PySide2.QtSensors.QSensor. userOrientationChanged ( userOrientation )
参数

userOrientation int