From e69f5c4e28759d13541c1f35c321d25e2a10c5c3 Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Mon, 27 Jan 2020 05:35:35 +0200 Subject: core/qtserialbluetooth.cpp: use QEventLoop for polling The Qt docs here: https://doc.qt.io/qt-5/qbluetoothsocket.html#details and here: https://doc.qt.io/qt-5/qabstractsocket.html#waitForReadyRead say that waitForReadyRead() does not work for QBluetoothSocket and that it's flaky on Windows for the underlying QAbstractSocket. Use a QEventLoop and a QTimer to poll the readyRead() signal. Signed-off-by: Lubomir I. Ivanov --- core/qtserialbluetooth.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp index 9d79d863b..6b47524de 100644 --- a/core/qtserialbluetooth.cpp +++ b/core/qtserialbluetooth.cpp @@ -212,7 +212,16 @@ static dc_status_t qt_serial_poll(void *io, int timeout) if (!device->socket) return DC_STATUS_INVALIDARGS; - if (device->socket->waitForReadyRead(timeout)) + + QEventLoop loop; + QTimer timer; + timer.setSingleShot(true); + loop.connect(&timer, SIGNAL(timeout()), SLOT(quit())); + loop.connect(device->socket, SIGNAL(readyRead()), SLOT(quit())); + timer.start(timeout); + loop.exec(); + + if (!timer.isActive()) return DC_STATUS_SUCCESS; return DC_STATUS_TIMEOUT; } -- cgit v1.2.3-70-g09d2