diff options
author | Lincoln Ramsay <lincoln.ramsay@nokia.com> | 2012-06-04 12:14:59 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-06-04 06:16:48 +0200 |
commit | f233e4266e20ea5ac06d51865b4da040b8e12fa9 (patch) | |
tree | d5423554b42d56ff0637c1a7be3bedf05c811bdd /src/sensors/qsensorbackend.cpp | |
parent | 030a56186e1697c0c31a858752f17ca18323dc95 (diff) |
setDataRates clobbers user-set data rate
Under normal conditions, dataRate is set/checked like so.
QSensor::setDataRate records the data rate. It can't be evaluated because we have
no backend. Upon getting a backend, we are notified of the available data rates.
Re-evaluate the previously-set dataRate after connecting to a backend.
The problem is that connectToBackend did not save the dataRate value until after
setDataRates was called and setDataRates was clobbering the dataRate property.
Two fixes will be made. connectToBackend will save the dataRate before creating
the backend and setDataRates will stop clobbering dataRate.
Also, setDataRates is now banned from being called outside of the constructor
because otherwise an available data rate may disappear during use.
Add a test case to verify that a previously-set data rate is not clobbered.
Change-Id: I9632b2c8ffcc6d48d9bc91f263b99028ee997ff9
Reviewed-by: Lorn Potter <lorn.potter@nokia.com>
Diffstat (limited to 'src/sensors/qsensorbackend.cpp')
-rw-r--r-- | src/sensors/qsensorbackend.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/sensors/qsensorbackend.cpp b/src/sensors/qsensorbackend.cpp index a576e5b9..7c65c59b 100644 --- a/src/sensors/qsensorbackend.cpp +++ b/src/sensors/qsensorbackend.cpp @@ -224,8 +224,7 @@ void QSensorBackend::addDataRate(qreal min, qreal max) setDataRates(otherSensor); \endcode - Note that this function should be called from the constructor so that the information - is available immediately. + Note that this function must be called from the constructor. \sa QSensor::availableDataRates, addDataRate() */ @@ -239,9 +238,12 @@ void QSensorBackend::setDataRates(const QSensor *otherSensor) qWarning() << "ERROR: Cannot call QSensorBackend::setDataRates with an invalid sensor"; return; } + if (m_sensor->isConnectedToBackend()) { + qWarning() << "ERROR: Cannot call QSensorBackend::setDataRates outside of the constructor"; + return; + } QSensorPrivate *d = m_sensor->d_func(); d->availableDataRates = otherSensor->availableDataRates(); - d->dataRate = otherSensor->dataRate(); } /*! |