QSensor¶
Inherited by: QAccelerometer, QAltimeter, QAmbientLightSensor, QAmbientTemperatureSensor, QCompass, QDistanceSensor, QGyroscope, QHolsterSensor, QHumiditySensor, QIRProximitySensor, QLidSensor, QLightSensor, QMagnetometer, QOrientationSensor, QPressureSensor, QProximitySensor, QRotationSensor, QTapSensor, QTiltSensor
Synopsis¶
Functions¶
def
addFilter
(filter)def
availableDataRates
()def
axesOrientationMode
()def
backend
()def
bufferSize
()def
connectToBackend
()def
currentOrientation
()def
dataRate
()def
description
()def
efficientBufferSize
()def
error
()def
filters
()def
identifier
()def
isActive
()def
isAlwaysOn
()def
isBusy
()def
isConnectedToBackend
()def
isFeatureSupported
(feature)def
maxBufferSize
()def
outputRange
()def
outputRanges
()def
reading
()def
removeFilter
(filter)def
setActive
(active)def
setAlwaysOn
(alwaysOn)def
setAxesOrientationMode
(axesOrientationMode)def
setBufferSize
(bufferSize)def
setCurrentOrientation
(currentOrientation)def
setDataRate
(rate)def
setEfficientBufferSize
(efficientBufferSize)def
setIdentifier
(identifier)def
setMaxBufferSize
(maxBufferSize)def
setOutputRange
(index)def
setSkipDuplicates
(skipDuplicates)def
setUserOrientation
(userOrientation)def
skipDuplicates
()def
type
()def
userOrientation
()
Signals¶
def
activeChanged
()def
alwaysOnChanged
()def
availableSensorsChanged
()def
axesOrientationModeChanged
(axesOrientationMode)def
bufferSizeChanged
(bufferSize)def
busyChanged
()def
currentOrientationChanged
(currentOrientation)def
dataRateChanged
()def
efficientBufferSizeChanged
(efficientBufferSize)def
maxBufferSizeChanged
(maxBufferSize)def
readingChanged
()def
sensorError
(error)def
skipDuplicatesChanged
(skipDuplicates)def
userOrientationChanged
(userOrientation)
Static functions¶
def
defaultSensorForType
(type)def
sensorTypes
()def
sensorsForType
(type)
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
andQRotationSensor
. 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 theAutomaticOrientation
mode, the reading values are automatically rotated by taking the current screen orientation into account. And finally, in theUserOrientation
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 theAxesOrientation
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
QSensor
(type[, parent=Q_NULLPTR])¶ - param type
QByteArray
- param parent
QObject
Construct the
type
sensor as a child ofparent
.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 inQAccelerometer
. These features will only work properly when creating a sensor instance from aQSensor
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 .
-
PySide2.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.See also
-
PySide2.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.See also
-
PySide2.QtSensors.QSensor.
activeChanged
()¶
-
PySide2.QtSensors.QSensor.
addFilter
(filter)¶ - Parameters
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.See also
-
PySide2.QtSensors.QSensor.
alwaysOnChanged
()¶
-
PySide2.QtSensors.QSensor.
availableDataRates
()¶ - Return type
-
PySide2.QtSensors.QSensor.
availableSensorsChanged
()¶
-
PySide2.QtSensors.QSensor.
axesOrientationMode
()¶ - Return type
See also
-
PySide2.QtSensors.QSensor.
axesOrientationModeChanged
(axesOrientationMode)¶ - Parameters
axesOrientationMode –
AxesOrientationMode
-
PySide2.QtSensors.QSensor.
backend
()¶ - Return type
-
PySide2.QtSensors.QSensor.
bufferSize
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
bufferSizeChanged
(bufferSize)¶ - Parameters
bufferSize –
int
-
PySide2.QtSensors.QSensor.
busyChanged
()¶
-
PySide2.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.See also
-
PySide2.QtSensors.QSensor.
currentOrientation
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
currentOrientationChanged
(currentOrientation)¶ - Parameters
currentOrientation –
int
-
PySide2.QtSensors.QSensor.
dataRate
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
dataRateChanged
()¶
-
static
PySide2.QtSensors.QSensor.
defaultSensorForType
(type)¶ - Parameters
type –
QByteArray
- Return type
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 fortype
.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 inSensors.conf
.
-
PySide2.QtSensors.QSensor.
description
()¶ - Return type
unicode
-
PySide2.QtSensors.QSensor.
efficientBufferSize
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
efficientBufferSizeChanged
(efficientBufferSize)¶ - Parameters
efficientBufferSize –
int
-
PySide2.QtSensors.QSensor.
error
()¶ - Return type
int
-
PySide2.QtSensors.QSensor.
filters
()¶ - Return type
Returns the filters currently attached to the sensor.
See also
-
PySide2.QtSensors.QSensor.
identifier
()¶ - Return type
QByteArray
See also
-
PySide2.QtSensors.QSensor.
isActive
()¶ - Return type
bool
-
PySide2.QtSensors.QSensor.
isAlwaysOn
()¶ - Return type
bool
-
PySide2.QtSensors.QSensor.
isBusy
()¶ - Return type
bool
-
PySide2.QtSensors.QSensor.
isConnectedToBackend
()¶ - Return type
bool
-
PySide2.QtSensors.QSensor.
isFeatureSupported
(feature)¶ - Parameters
feature –
Feature
- 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()
orstart()
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
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
maxBufferSizeChanged
(maxBufferSize)¶ - Parameters
maxBufferSize –
int
-
PySide2.QtSensors.QSensor.
outputRange
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
outputRanges
()¶ - Return type
-
PySide2.QtSensors.QSensor.
reading
()¶ - Return type
QSensorReading
-
PySide2.QtSensors.QSensor.
readingChanged
()¶
-
PySide2.QtSensors.QSensor.
removeFilter
(filter)¶ - Parameters
filter –
QSensorFilter
Remove
filter
from the sensor.See also
-
PySide2.QtSensors.QSensor.
sensorError
(error)¶ - Parameters
error –
int
-
static
PySide2.QtSensors.QSensor.
sensorTypes
()¶ - Return type
Returns a list of all sensor types.
-
static
PySide2.QtSensors.QSensor.
sensorsForType
(type)¶ - Parameters
type –
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.
-
PySide2.QtSensors.QSensor.
setActive
(active)¶ - Parameters
active –
bool
See also
-
PySide2.QtSensors.QSensor.
setAlwaysOn
(alwaysOn)¶ - Parameters
alwaysOn –
bool
See also
-
PySide2.QtSensors.QSensor.
setAxesOrientationMode
(axesOrientationMode)¶ - Parameters
axesOrientationMode –
AxesOrientationMode
See also
-
PySide2.QtSensors.QSensor.
setBufferSize
(bufferSize)¶ - Parameters
bufferSize –
int
See also
-
PySide2.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 theuserOrientation
property changes.See also
-
PySide2.QtSensors.QSensor.
setDataRate
(rate)¶ - Parameters
rate –
int
See also
-
PySide2.QtSensors.QSensor.
setEfficientBufferSize
(efficientBufferSize)¶ - Parameters
efficientBufferSize –
int
Sets the efficient buffer size to
efficientBufferSize
. This is to be called from the backend.See also
-
PySide2.QtSensors.QSensor.
setIdentifier
(identifier)¶ - Parameters
identifier –
QByteArray
See also
-
PySide2.QtSensors.QSensor.
setMaxBufferSize
(maxBufferSize)¶ - Parameters
maxBufferSize –
int
Sets the maximum buffer size to
maxBufferSize
. This is to be called from the backend.See also
-
PySide2.QtSensors.QSensor.
setOutputRange
(index)¶ - Parameters
index –
int
See also
-
PySide2.QtSensors.QSensor.
setSkipDuplicates
(skipDuplicates)¶ - Parameters
skipDuplicates –
bool
Sets the duplicate skipping to
skipDuplicates
.See also
-
PySide2.QtSensors.QSensor.
setUserOrientation
(userOrientation)¶ - Parameters
userOrientation –
int
See also
-
PySide2.QtSensors.QSensor.
skipDuplicates
()¶ - Return type
bool
See also
-
PySide2.QtSensors.QSensor.
skipDuplicatesChanged
(skipDuplicates)¶ - Parameters
skipDuplicates –
bool
-
PySide2.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
-
PySide2.QtSensors.QSensor.
stop
()¶ Stop retrieving values from the sensor.
This releases the sensor so that other processes can use it.
See also
busy
-
PySide2.QtSensors.QSensor.
type
()¶ - Return type
QByteArray
-
PySide2.QtSensors.QSensor.
userOrientation
()¶ - Return type
int
See also
-
PySide2.QtSensors.QSensor.
userOrientationChanged
(userOrientation)¶ - Parameters
userOrientation –
int
© 2018 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.