src/sensors/qsensor.cpp
changeset 5 603d3f8b6302
parent 0 876b1a06bc25
equal deleted inserted replaced
3:e4ebb16b39ea 5:603d3f8b6302
   296 
   296 
   297 /*!
   297 /*!
   298     Start retrieving values from the sensor.
   298     Start retrieving values from the sensor.
   299     Returns true if the sensor was started, false otherwise.
   299     Returns true if the sensor was started, false otherwise.
   300 
   300 
   301     Note that the sensor may fail to start for several reasons.
   301     The sensor may fail to start for several reasons.
       
   302 
       
   303     Once an application has started a sensor it must wait until the sensor receives a
       
   304     new value before it can query the sensor's values. This is due to how the sensor
       
   305     receives values from the system. Sensors do not (in general) poll for new values,
       
   306     rather new values are pushed to the sensors as they happen.
       
   307 
       
   308     For example, this code will not work as intended.
       
   309 
       
   310     \badcode
       
   311     sensor->start();
       
   312     sensor->reading()->x(); // no data available
       
   313     \endcode
       
   314 
       
   315     To work correctly, the code that accesses the reading should ensure the
       
   316     readingChanged() signal has been emitted.
       
   317 
       
   318     \code
       
   319         connect(sensor, SIGNAL(readingChanged()), this, SLOT(checkReading()));
       
   320         sensor->start();
       
   321     }
       
   322     void MyClass::checkReading() {
       
   323         sensor->reading()->x();
       
   324     \endcode
   302 
   325 
   303     \sa QSensor::busy
   326     \sa QSensor::busy
   304 */
   327 */
   305 bool QSensor::start()
   328 bool QSensor::start()
   306 {
   329 {
   337 
   360 
   338     The reading class provides access to sensor readings.
   361     The reading class provides access to sensor readings.
   339 
   362 
   340     Note that this will return 0 until a sensor backend is connected to a backend.
   363     Note that this will return 0 until a sensor backend is connected to a backend.
   341 
   364 
   342     \sa isConnectedToBackend()
   365     Also note that readings are not immediately available after start() is called.
       
   366     Applications must wait for the readingChanged() signal to be emitted.
       
   367 
       
   368     \sa isConnectedToBackend(), start()
   343 */
   369 */
   344 
   370 
   345 QSensorReading *QSensor::reading() const
   371 QSensorReading *QSensor::reading() const
   346 {
   372 {
   347     return d->cache_reading;
   373     return d->cache_reading;
   386 
   412 
   387 /*!
   413 /*!
   388     \fn QSensor::readingChanged()
   414     \fn QSensor::readingChanged()
   389 
   415 
   390     This signal is emitted when the reading has changed.
   416     This signal is emitted when the reading has changed.
       
   417 
       
   418     Before this signal has been emitted for the first time, the sensor reading will
       
   419     have uninitialized data.
       
   420 
       
   421     \sa start()
   391 */
   422 */
   392 
   423 
   393 /*!
   424 /*!
   394     \property QSensor::outputRanges
   425     \property QSensor::outputRanges
   395     \brief a list of output ranges the sensor supports.
   426     \brief a list of output ranges the sensor supports.