From db549d815d5ca0a0075b571f9b0a22ad5db37c03 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Wed, 20 Nov 2013 18:39:50 +0000 Subject: Drop the empty data check in favor of proper error code handling Change-Id: Iad0f2c58a4f52daebd02a71fd7b404cb283602dc Reviewed-by: Denis Shienkov Reviewed-by: Sergey Belyashov --- examples/serialport/creadersync/main.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/serialport/creadersync/main.cpp b/examples/serialport/creadersync/main.cpp index cd10b8e..188d7b8 100644 --- a/examples/serialport/creadersync/main.cpp +++ b/examples/serialport/creadersync/main.cpp @@ -99,9 +99,12 @@ int main(int argc, char *argv[]) while (serialPort.waitForReadyRead(5000)) readData.append(serialPort.readAll()); - if (readData.isEmpty()) { - standardOutput << QObject::tr("Either no data was currently available for reading, or an error occurred for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; + if (serialPort.error() == QSerialPort::ReadError) { + standardOutput << QObject::tr("Failed to read from port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; + } else if (serialPort.error() == QSerialPort::TimeoutError) { + standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(serialPortName) << endl; + return 0; } standardOutput << QObject::tr("Data successfully received from port %1").arg(serialPortName) << endl; -- cgit v1.2.1