Commit 2807a409 authored by Arjen Hiemstra's avatar Arjen Hiemstra
Browse files

Connect/disconnect from SensorDaemonInterface when Sensor::enabled changes

setSensorId only connects when the sensor is enabled, which means we may
not yet be connected if the sensor is created in a disabled context.
Rather than always connecting, make the connections explicit only
enabled when the sensor is enabled, so we do not do unneccessary work.
parent f0512a6a
......@@ -248,12 +248,17 @@ void Sensor::onValueChanged(const QString &sensorId, const QVariant &value)
void Sensor::onEnabledChanged()
if (enabled()) {
connect(SensorDaemonInterface::instance(), &SensorDaemonInterface::metaDataChanged, this, &Sensor::onMetaDataChanged, Qt::UniqueConnection);
connect(SensorDaemonInterface::instance(), &SensorDaemonInterface::valueChanged, this, &Sensor::onValueChanged, Qt::UniqueConnection);
// Force an update of metadata and data, since that may have changed
// while we were disabled.
} else {
disconnect(SensorDaemonInterface::instance(), &SensorDaemonInterface::metaDataChanged, this, &Sensor::onMetaDataChanged);
disconnect(SensorDaemonInterface::instance(), &SensorDaemonInterface::valueChanged, this, &Sensor::onValueChanged);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment