QSensor Class ReferenceThe QSensor class represents a single hardware sensor. More... #include <QSensor> Inherits QObject. Inherited by QAccelerometer, QAmbientLightSensor, QCompass, QMagnetometer, QOrientationSensor, QProximitySensor, QRotationSensor, and QTapSensor. Properties
Public Functions
Public Slots
Signals
Static Public Members
Related Non-Members
Additional Inherited Members
Detailed DescriptionThe QSensor class represents a single hardware sensor. The life cycle of a sensor is typically:
The sensor data is delivered via QSensorData and its sub-classes. Property Documentation
|
bool | isActive () const |
void | setActive ( bool active ) |
Notifier signal:
void | activeChanged () |
This property holds the data rates that the sensor supports.
This is a list of the data rates that the sensor supports. Measured in Hertz.
Entries in the list can represent discrete rates or a continuous range of rates. A discrete rate is noted by having both values the same.
See the sensor_explorer example for an example of how to interpret and use this information.
Access functions:
qrangelist | availableDataRates () const |
See also QSensor::dataRate.
This property holds a value to indicate if the sensor is busy.
Some sensors may be on the system but unavailable for use. This function will return true if the sensor is busy. You will not be able to start() the sensor.
Note that this function does not return true if you are using the sensor, only if another process is using the sensor.
Access functions:
bool | isBusy () const |
See also busyChanged().
This property holds a value indicating if the sensor has connected to a backend.
A sensor that has not been connected to a backend cannot do anything useful.
Call the connectToBackend() method to force the sensor to connect to a backend immediately. This is automatically called if you call start() so you only need to do this if you need access to sensor properties (ie. to poll the sensor's meta-data before you use it).
Access functions:
bool | isConnectedToBackend () const |
This property holds the data rate that the sensor should be run at.
Measured in Hertz.
The data rate is the maximum frequency at which the sensor can detect changes.
Setting this property is not portable and can cause conflicts with other applications. Check with the sensor backend and platform documentation for any policy regarding multiple applications requesting a data rate.
The default value (0) means that the app does not care what the data rate is. Applications should consider using a timer-based poll of the current value or ensure that the code that processes values can run very quickly as the platform may provide updates hundreds of times each second.
This should be set before calling start() because the sensor may not notice changes to this value while it is running.
Note that there is no mechanism to determine the current data rate in use by the platform.
Access functions:
int | dataRate () const |
void | setDataRate ( int rate ) |
See also QSensor::availableDataRates.
This property holds a descriptive string for the sensor.
Access functions:
QString | description () const |
This property holds the last error code set on the sensor.
Note that error codes are sensor-specific.
Access functions:
int | error () const |
Notifier signal:
void | sensorError ( int error ) |
This property holds the output range in use by the sensor.
This value represents the index in the QSensor::outputRanges list to use.
Setting this property is not portable and can cause conflicts with other applications. Check with the sensor backend and platform documentation for any policy regarding multiple applications requesting an output range.
The default value (-1) means that the app does not care what the output range is.
Note that there is no mechanism to determine the current output range in use by the platform.
Access functions:
int | outputRange () const |
void | setOutputRange ( int index ) |
See also QSensor::outputRanges.
This property holds a list of output ranges the sensor supports.
A sensor may have more than one output range. Typically this is done to give a greater measurement range at the cost of lowering accuracy.
The qoutputrangelist type exists for the benefit of the meta-type system. It is just a typedef.
typedef qoutputrangelist QList<qoutputrange>;
Access functions:
qoutputrangelist | outputRanges () const |
See also QSensor::outputRange and qoutputrange.
This property holds the reading class.
The reading class provides access to sensor readings.
Note that this will return 0 until a sensor backend is connected to a backend.
Also note that readings are not immediately available after start() is called. Applications must wait for the readingChanged() signal to be emitted.
Access functions:
QSensorReading * | reading () const |
Notifier signal:
void | readingChanged () |
See also isConnectedToBackend() and start().
This property holds the backend identifier for the sensor.
Note that the identifier is filled out automatically when the sensor is connected to a backend. If you want to connect a specific backend, you should call setIdentifier() before connectToBackend().
Access functions:
QByteArray | identifier () const |
void | setIdentifier ( const QByteArray & identifier ) |
This property holds the type of the sensor.
Access functions:
QByteArray | type () const |
Construct the type sensor as a child of parent.
Destroy the sensor. Stops the sensor if it has not already been stopped.
This signal is emitted when the QSensor::active property has changed.
See also QSensor::active.
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.
This signal is emitted when the busy state changes. This can be used to grab a sensor when it becomes available.
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.
See also Determining the default sensor for a type.
This signal is emitted when the reading has changed.
Before this signal has been emitted for the first time, the sensor reading will have uninitialized data.
See also start().
Remove filter from the sensor.
See also QSensorFilter.
This signal is emitted when an error code is set on the sensor. Note that some errors will cause the sensor to stop working. You should call isActive() to determine if the sensor is still running.
Returns a list of all sensor types.
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.
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 QSensor::busy.
Stop retrieving values from the sensor.
This releases the sensor so that other processes can use it.
See also QSensor::busy.
Sensor timestamps are represented by this typedef which is a 64 bit unsigned integer.
Timestamps values are microseconds since a fixed point. You can use timestamps to see how far apart two sensor readings are.
Note that sensor timestamps from different sensors may not be directly comparable (as they may choose different fixed points for their reference).