Use waitFor instead of timer

See e79bede0aa. We rather use wait in combination
with spinning the event loop.

Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
This commit is contained in:
Jan Mulder 2017-07-03 20:56:44 +02:00 committed by Dirk Hohndel
parent f6768cedf3
commit 6031692a39
2 changed files with 4 additions and 8 deletions

View file

@ -60,7 +60,6 @@ void BLEObject::characteristcStateChanged(const QLowEnergyCharacteristic &c, con
Q_UNUSED(c)
receivedPackets.append(value);
waitForPacket.exit();
}
void BLEObject::writeCompleted(const QLowEnergyDescriptor &d, const QByteArray &value)
@ -155,13 +154,11 @@ dc_status_t BLEObject::read(void *data, size_t size, size_t *actual)
if (list.isEmpty())
return DC_STATUS_IO;
QTimer timer;
int msec = BLE_TIMEOUT;
timer.setSingleShot(true);
waitForPacket.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
timer.start(msec);
waitForPacket.exec();
while (msec > 0 && receivedPackets.isEmpty()) {
waitFor(100);
msec -= 100;
};
}
// Still no packet?

View file

@ -36,7 +36,6 @@ private:
QLowEnergyController *controller = nullptr;
QList<QByteArray> receivedPackets;
QEventLoop waitForPacket;
bool isCharacteristicWritten;
dc_user_device_t *device;