Since: 1.0

#include <QtSensors/QProximitySensor>

More information will be added here shortly. For now, you'll find more extensive information about this class in the Qt reference for QProximitySensor


The QProximitySensor class is a convenience wrapper around QSensor.

The only behavioural difference is that this class sets the type properly.

This class also features a reading() function that returns a QProximityReading instead of a QSensorReading.

For details about how the sensor works, see QProximityReading.




Properties Index

Only has inherited properties

QtMobility::qrangelistavailableDataRates [read-only]Inherited
boolbusy [read-only]Inherited
boolconnectedToBackend [read-only]Inherited
QStringdescription [read-only]Inherited
intefficientBufferSize [read-only]Inherited
interror [read-only]Inherited
intmaxBufferSize [read-only]Inherited
QtMobility::qoutputrangelistoutputRanges [read-only]Inherited
QSensorReadingreading [read-only]Inherited

Public Static Attributes Index

char const *consttype

Public Functions Index

QProximitySensor (QObject *parent=0)
virtual ~QProximitySensor ()
QProximityReading *reading () const
voidaddFilter (QSensorFilter *filter)Inherited
qrangelistavailableDataRates () const Inherited
intbufferSize () const Inherited
Q_INVOKABLE boolconnectToBackend ()Inherited
intdataRate () const Inherited
QStringdescription () const Inherited
intefficientBufferSize () const Inherited
interror () const Inherited
QList< QSensorFilter * >filters () const Inherited
QByteArrayidentifier () const Inherited
boolisActive () const Inherited
boolisAlwaysOn () const Inherited
boolisBusy () const Inherited
boolisConnectedToBackend () const Inherited
intmaxBufferSize () const Inherited
intoutputRange () const Inherited
qoutputrangelistoutputRanges () const Inherited
QSensor (const QByteArray &type, QObject *parent=0)Inherited
voidremoveFilter (QSensorFilter *filter)Inherited
voidsetActive (bool active)Inherited
voidsetAlwaysOn (bool alwaysOn)Inherited
voidsetBufferSize (int bufferSize)Inherited
voidsetDataRate (int rate)Inherited
voidsetEfficientBufferSize (int efficientBufferSize)Inherited
voidsetIdentifier (const QByteArray &identifier)Inherited
voidsetMaxBufferSize (int maxBufferSize)Inherited
voidsetOutputRange (int index)Inherited
voidsetSkipDuplicates (bool skipDuplicates)Inherited
boolskipDuplicates () const Inherited
QByteArraytype () const Inherited

Static Public Functions Index

Only has inherited static public functions

QByteArraydefaultSensorForType (const QByteArray &type)Inherited
QList< QByteArray >sensorsForType (const QByteArray &type)Inherited
QList< QByteArray >sensorTypes ()Inherited

Protected Functions Index

Only has inherited protected functions

QSensorPrivate *d_func () const Inherited
QSensor (const QByteArray &type, QSensorPrivate *dd, QObject *parent=0)Inherited

Public Slots Index

Only has inherited public slots

boolstart ()Inherited
voidstop ()Inherited

Signals Index

Only has inherited signals

voidactiveChanged ()Inherited
voidalwaysOnChanged ()Inherited
voidavailableSensorsChanged ()Inherited
voidbufferSizeChanged (int bufferSize)Inherited
voidbusyChanged ()Inherited
voiddataRateChanged ()Inherited
voidefficientBufferSizeChanged (int efficientBufferSize)Inherited
voidmaxBufferSizeChanged (int maxBufferSize)Inherited
voidreadingChanged ()Inherited
voidsensorError (int error)Inherited
voidskipDuplicatesChanged (bool skipDuplicates)Inherited


(Only has inherited properties)

bool activeInherited

a value to indicate if the sensor is active.

Note that setting this value to true will not have an immediate effect. Instead, the sensor will be started once the event loop has been reached.



bool alwaysOnInherited

a value to indicate if the sensor should remain running when the screen is off.

Some platforms have a policy of suspending sensors when the screen turns off. Setting this property to true will ensure the sensor continues to run.

QtMobility::qrangelist availableDataRatesInherited[read-only]

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.

Note that this information is not mandatory as not all sensors have a rate at which they run. In such cases, the list will be empty.



int bufferSizeInherited

This property holds the size of the buffer.

By default, the buffer size is 1, which means no buffering. If the maximum buffer size is 1, then buffering is not supported by the sensor.

Setting bufferSize greater than maxBufferSize will cause maxBufferSize to be used.

Buffering is turned on when bufferSize is greater than 1. The sensor will collect the requested number of samples and deliver them all to the application at one time. They will be delivered to the application as a burst of changed readings so it is particularly important that the application processes each reading immediately or saves the values somewhere else.

If stop() is called when buffering is on-going, the partial buffer is not delivered.

When the sensor is started with buffering option, values are collected from that moment onwards. There is no pre-existing buffer that can be utilized.

Some backends like Blackberry only support enabling or disabling the buffer and do not give control over the size. In this case, the maxBufferSize and efficientBufferSize properties might not be set at all, even though buffering is supported. Setting the bufferSize property to any value greater than 1 will enable buffering. After the sensor has been started, the bufferSize property will be set to the actual value by the backend.

On Blackberry, buffering will not wait until the buffer is full to deliver new readings. Instead, the buffer will be used if the backend does not manage to retrieve the readings in time, for example when the event loop is blocked for too long. Without a buffer, these readings would simply be dropped.

bool busyInherited[read-only]

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.

See also:




bool connectedToBackendInherited[read-only]

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


int dataRateInherited

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.



QString descriptionInherited[read-only]

a descriptive string for the sensor.



int efficientBufferSizeInherited[read-only]

The property holds the most efficient buffer size.

Normally this is 1 (which means no particular size is most efficient). Some sensor drivers have a FIFO buffer which makes it more efficient to deliver the FIFO's size worth of readings at one time.

int errorInherited[read-only]

the last error code set on the sensor.

Note that error codes are sensor-specific.


int maxBufferSizeInherited[read-only]

The property holds the maximum buffer size.

Note that this may be 1, in which case the sensor does not support any form of buffering.

int outputRangeInherited

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.



QtMobility::qoutputrangelist outputRangesInherited[read-only]

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.

Note that this information is not mandatory. This information is typically only available for sensors that have selectable output ranges (such as typical accelerometers).



QSensorReading readingInherited[read-only]

the reading class.

The reading class provides access to sensor readings. The reading object is a volatile cache of the most recent sensor reading that has been received so the application should process readings immediately or save the values somewhere for later processing.

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.

See also:

isConnectedToBackend(), start()



QByteArray sensoridInherited

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().


bool skipDuplicatesInherited

Indicates whether duplicate reading values should be omitted.

When duplicate skipping is enabled, successive readings with the same or very similar values are omitted and skipped. This helps reducing the amount of processing done, as less sensor readings are made available. As a consequence, readings arrive at an irregular interval.

Duplicate skipping is not just enabled for readings that are exactly the same, but also for readings that are quite similar, as each sensor has a bit of jitter even if the device is not moved.

Support for this property depends on the backend. It is disabled by default.

Duplicate skipping can only be changed while the sensor is not active.

Public Static Attributes

char const *const type ()

the type of the sensor.



Public Functions

QProximitySensor (

Construct the sensor as a child of parent.



virtual~QProximitySensor ()


Stops the sensor if it has not already been stopped.


QProximityReading * reading ()

Returns the reading class for this sensor.



void addFilter (Inherited

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:




qrangelist availableDataRates ()Inherited

int bufferSize ()Inherited

Q_INVOKABLE bool connectToBackend ()Inherited

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:




int dataRate ()Inherited

QString description ()Inherited

int efficientBufferSize ()Inherited

int error ()Inherited

QList< QSensorFilter * > filters ()Inherited

Returns the filters currently attached to the sensor.

See also:




QByteArray identifier ()Inherited

bool isActive ()Inherited

bool isAlwaysOn ()Inherited

bool isBusy ()Inherited

bool isConnectedToBackend ()Inherited

int maxBufferSize ()Inherited

int outputRange ()Inherited

qoutputrangelist outputRanges ()Inherited

QSensor (Inherited

Construct the type sensor as a child of parent.



void removeFilter (Inherited

Remove filter from the sensor.

See also:




void setActive (
  • boolactive)

void setAlwaysOn (
  • boolalwaysOn)

void setBufferSize (
  • intbufferSize)

void setDataRate (
  • intrate)

void setEfficientBufferSize (
  • intefficientBufferSize)

Sets the efficient buffer size to efficientBufferSize.

This is to be called from the backend.

void setIdentifier (Inherited

void setMaxBufferSize (
  • intmaxBufferSize)

Sets the maximum buffer size to maxBufferSize.

This is to be called from the backend.

void setOutputRange (
  • intindex)

void setSkipDuplicates (
  • boolskipDuplicates)

Sets the duplicate skipping to skipDuplicates.

bool skipDuplicates ()Inherited

QByteArray type ()Inherited

Static Public Functions

(Only has inherited static public functions)

QByteArray defaultSensorForType (Inherited

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

See also:

{Determining the default sensor for a type}



QList< QByteArray > sensorsForType (Inherited

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.


QList< QByteArray > sensorTypes ()Inherited

Returns a list of all sensor types.



Protected Functions

(Only has inherited protected functions)

QSensorPrivate * d_func ()Inherited

QSensor (Inherited

Public Slots

(Only has inherited public slots)

bool start ()Inherited

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()));
    void MyClass::checkReading() {
See also:




void stop ()Inherited

Stop retrieving values from the sensor.

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

See also:





(Only has inherited signals)

void activeChanged ()Inherited

This signal is emitted when the QSensor::active property has changed.

See also:




void alwaysOnChanged ()Inherited

This signal is emitted when the alwaysOn property changes.

void availableSensorsChanged ()Inherited

This signal is emitted when the list of available sensors has changed.

The sensors available to a program will not generally change over time however some of the avilable sensors may represent hardware that is not permanently connected. For example, a game controller that is connected via bluetooth would become available when it was on and would become unavailable when it was off.

void bufferSizeChanged (
  • intbufferSize)

void busyChanged ()Inherited

This signal is emitted when the sensor is no longer busy.

This can be used to grab a sensor when it becomes available.

    if (sensor.isBusy()) {
        // need to wait for busyChanged signal and try again


void dataRateChanged ()Inherited

void efficientBufferSizeChanged (
  • intefficientBufferSize)

void maxBufferSizeChanged (
  • intmaxBufferSize)

void readingChanged ()Inherited

This signal is emitted when a new sensor reading is received.

The sensor reading can be found in the QSensor::reading property. Note that the reading object is a volatile cache of the most recent sensor reading that has been received so the application should process the reading immediately or save the values somewhere for later processing.

Before this signal has been emitted for the first time, the reading object will have uninitialized data.

See also:




void sensorError (
  • interror)

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.


void skipDuplicatesChanged (
  • boolskipDuplicates)

Last modified: 2015-03-26

Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus