QSensor

The QSensor class represents a single hardware sensor. More

Inheritance diagram of PySide6.QtSensors.QSensor

Inherited by: QTiltSensor, QTapSensor, QRotationSensor, QProximitySensor, QPressureSensor, QOrientationSensor, QMagnetometer, QLightSensor, QLidSensor, QIRProximitySensor, QHumiditySensor, QGyroscope, QCompass, QAmbientTemperatureSensor, QAmbientLightSensor, QAccelerometer

Synopsis

Functions

Static functions

Detailed Description

The life cycle of a sensor is typically:

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

  • Setup as required by the application.

  • Start receiving values.

  • Sensor data is used by the application.

  • Stop receiving values.

The sensor data is delivered via QSensorReading and its sub-classes.

Orientation

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() with the AxesOrientation flag.

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.

See also

QSensorReading

class PySide6.QtSensors.QSensor(type[, parent=None])
Parameters

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::sensorType, 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 subclass.

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 .

PySide6.QtSensors.QSensor.Feature

Lists optional features a backend might support.

The features common to all sensor types are:

Constant

Description

QSensor.Buffering

The backend supports buffering of readings, controlled by the bufferSize property.

QSensor.AlwaysOn

The backend supports changing the policy on whether to suspend when idle, controlled by the alwaysOn property.

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 are:

Constant

Description

QSensor.GeoValues

The backend supports returning geo values, which can be controlled with the returnGeoValues property.

The features of QLightSensor are:

Constant

Description

QSensor.FieldOfView

The backend specifies its field of view, which can be read from the fieldOfView property.

The features of QAccelerometer are:

Constant

Description

QSensor.AccelerationMode

The backend supports switching the acceleration mode of the acceleromter with the accelerationMode property.

The features of QPressureSensor are:

Constant

Description

QSensor.PressureSensorTemperature

The backend provides the pressure sensor’s die temperature

The features of all orientable sensors are:

Constant

Description

QSensor.AxesOrientation

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

PySide6.QtSensors.QSensor.AxesOrientationMode

Describes how reading values are affected by the screen orientation.

Constant

Description

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

PySide6.QtSensors.QSensor.activeChanged()
PySide6.QtSensors.QSensor.addFilter(filter)
Parameters

filterPySide6.QtSensors.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.

See also

QSensorFilter

PySide6.QtSensors.QSensor.alwaysOnChanged()
PySide6.QtSensors.QSensor.availableDataRates()
Return type

PySide6.QtSensors.QSensor.availableSensorsChanged()
PySide6.QtSensors.QSensor.axesOrientationMode()
Return type

AxesOrientationMode

PySide6.QtSensors.QSensor.axesOrientationModeChanged(axesOrientationMode)
Parameters

axesOrientationModeAxesOrientationMode

PySide6.QtSensors.QSensor.backend()
Return type

PySide6.QtSensors.QSensorBackend

PySide6.QtSensors.QSensor.bufferSize()
Return type

int

See also

setBufferSize()

PySide6.QtSensors.QSensor.bufferSizeChanged(bufferSize)
Parameters

bufferSize – int

PySide6.QtSensors.QSensor.busyChanged()
PySide6.QtSensors.QSensor.connectToBackend()
Return type

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.

PySide6.QtSensors.QSensor.currentOrientation()
Return type

int

PySide6.QtSensors.QSensor.currentOrientationChanged(currentOrientation)
Parameters

currentOrientation – int

PySide6.QtSensors.QSensor.dataRate()
Return type

int

See also

setDataRate()

PySide6.QtSensors.QSensor.dataRateChanged()
static PySide6.QtSensors.QSensor.defaultSensorForType(type)
Parameters

typePySide6.QtCore.QByteArray

Return type

PySide6.QtCore.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.

PySide6.QtSensors.QSensor.description()
Return type

str

PySide6.QtSensors.QSensor.efficientBufferSize()
Return type

int

PySide6.QtSensors.QSensor.efficientBufferSizeChanged(efficientBufferSize)
Parameters

efficientBufferSize – int

PySide6.QtSensors.QSensor.error()
Return type

int

PySide6.QtSensors.QSensor.filters()
Return type

Returns the filters currently attached to the sensor.

See also

QSensorFilter

PySide6.QtSensors.QSensor.identifier()
Return type

PySide6.QtCore.QByteArray

See also

setIdentifier()

PySide6.QtSensors.QSensor.identifierChanged()
PySide6.QtSensors.QSensor.isActive()
Return type

bool

PySide6.QtSensors.QSensor.isAlwaysOn()
Return type

bool

PySide6.QtSensors.QSensor.isBusy()
Return type

bool

PySide6.QtSensors.QSensor.isConnectedToBackend()
Return type

bool

PySide6.QtSensors.QSensor.isFeatureSupported(feature)
Parameters

featureFeature

Return type

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.

PySide6.QtSensors.QSensor.maxBufferSize()
Return type

int

PySide6.QtSensors.QSensor.maxBufferSizeChanged(maxBufferSize)
Parameters

maxBufferSize – int

PySide6.QtSensors.QSensor.outputRange()
Return type

int

See also

setOutputRange()

PySide6.QtSensors.QSensor.outputRanges()
Return type

PySide6.QtSensors.QSensor.reading()
Return type

PySide6.QtSensors.QSensorReading

PySide6.QtSensors.QSensor.readingChanged()
PySide6.QtSensors.QSensor.removeFilter(filter)
Parameters

filterPySide6.QtSensors.QSensorFilter

Remove filter from the sensor.

See also

QSensorFilter

PySide6.QtSensors.QSensor.sensorError(error)
Parameters

error – int

static PySide6.QtSensors.QSensor.sensorTypes()
Return type

Returns a list of all sensor types.

static PySide6.QtSensors.QSensor.sensorsForType(type)
Parameters

typePySide6.QtCore.QByteArray

Return type

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.

PySide6.QtSensors.QSensor.setActive(active)
Parameters

active – bool

See also

isActive()

PySide6.QtSensors.QSensor.setAlwaysOn(alwaysOn)
Parameters

alwaysOn – bool

See also

isAlwaysOn()

PySide6.QtSensors.QSensor.setAxesOrientationMode(axesOrientationMode)
Parameters

axesOrientationModeAxesOrientationMode

PySide6.QtSensors.QSensor.setBufferSize(bufferSize)
Parameters

bufferSize – int

See also

bufferSize()

PySide6.QtSensors.QSensor.setCurrentOrientation(currentOrientation)
Parameters

currentOrientation – int

Sets the current screen orientation to currentOrientation. This is to be called from the backend whenever the screen orientation or the userOrientation property changes.

PySide6.QtSensors.QSensor.setDataRate(rate)
Parameters

rate – int

See also

dataRate()

PySide6.QtSensors.QSensor.setEfficientBufferSize(efficientBufferSize)
Parameters

efficientBufferSize – int

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

PySide6.QtSensors.QSensor.setIdentifier(identifier)
Parameters

identifierPySide6.QtCore.QByteArray

See also

identifier()

PySide6.QtSensors.QSensor.setMaxBufferSize(maxBufferSize)
Parameters

maxBufferSize – int

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

See also

maxBufferSize()

PySide6.QtSensors.QSensor.setOutputRange(index)
Parameters

index – int

See also

outputRange()

PySide6.QtSensors.QSensor.setSkipDuplicates(skipDuplicates)
Parameters

skipDuplicates – bool

Sets the duplicate skipping to skipDuplicates.

See also

skipDuplicates()

PySide6.QtSensors.QSensor.setUserOrientation(userOrientation)
Parameters

userOrientation – int

PySide6.QtSensors.QSensor.skipDuplicates()
Return type

bool

PySide6.QtSensors.QSensor.skipDuplicatesChanged(skipDuplicates)
Parameters

skipDuplicates – bool

PySide6.QtSensors.QSensor.start()
Return type

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() signal has been emitted.

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

See also

busy

PySide6.QtSensors.QSensor.stop()

Stop retrieving values from the sensor.

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

See also

busy

PySide6.QtSensors.QSensor.type()
Return type

PySide6.QtCore.QByteArray

PySide6.QtSensors.QSensor.userOrientation()
Return type

int

PySide6.QtSensors.QSensor.userOrientationChanged(userOrientation)
Parameters

userOrientation – int