diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2017-09-27 19:31:15 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2017-10-05 06:44:51 +0000 |
commit | 466705128376bd5d60ec23eec7af37d3bf6649fe (patch) | |
tree | c8b4b4b7ac72753abde602ecbbae907f9a5c8aab /examples/serialport/creaderasync/serialportreader.cpp | |
parent | da09f8f01d13ff467f0a628b6348aa9300160875 (diff) |
Revamp the Console Asynchronous Reader Example
* Use the 'const' keywords more.
* Split very long lines.
* Remove QT_USE_NAMESPACE macro.
* Update includes to common style.
* Use more member class initializations.
* Remove empy dtor.
Task-number: QTBUG-60652
Change-Id: I9cd0e010f2489993141ed4e24557e492201c98b6
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'examples/serialport/creaderasync/serialportreader.cpp')
-rw-r--r-- | examples/serialport/creaderasync/serialportreader.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/examples/serialport/creaderasync/serialportreader.cpp b/examples/serialport/creaderasync/serialportreader.cpp index f85dd8a7..a701839b 100644 --- a/examples/serialport/creaderasync/serialportreader.cpp +++ b/examples/serialport/creaderasync/serialportreader.cpp @@ -52,25 +52,18 @@ #include <QCoreApplication> -QT_USE_NAMESPACE - -SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent) - : QObject(parent) - , m_serialPort(serialPort) - , m_standardOutput(stdout) +SerialPortReader::SerialPortReader(QSerialPort *serialPort, QObject *parent) : + QObject(parent), + m_serialPort(serialPort), + m_standardOutput(stdout) { connect(m_serialPort, &QSerialPort::readyRead, this, &SerialPortReader::handleReadyRead); - connect(m_serialPort, static_cast<void (QSerialPort::*)(QSerialPort::SerialPortError)>(&QSerialPort::error), - this, &SerialPortReader::handleError); + connect(m_serialPort, &QSerialPort::errorOccurred, this, &SerialPortReader::handleError); connect(&m_timer, &QTimer::timeout, this, &SerialPortReader::handleTimeout); m_timer.start(5000); } -SerialPortReader::~SerialPortReader() -{ -} - void SerialPortReader::handleReadyRead() { m_readData.append(m_serialPort->readAll()); @@ -82,9 +75,14 @@ void SerialPortReader::handleReadyRead() void SerialPortReader::handleTimeout() { if (m_readData.isEmpty()) { - m_standardOutput << QObject::tr("No data was currently available for reading from port %1").arg(m_serialPort->portName()) << endl; + m_standardOutput << QObject::tr("No data was currently available " + "for reading from port %1") + .arg(m_serialPort->portName()) + << endl; } else { - m_standardOutput << QObject::tr("Data successfully received from port %1").arg(m_serialPort->portName()) << endl; + m_standardOutput << QObject::tr("Data successfully received from port %1") + .arg(m_serialPort->portName()) + << endl; m_standardOutput << m_readData << endl; } @@ -94,7 +92,11 @@ void SerialPortReader::handleTimeout() void SerialPortReader::handleError(QSerialPort::SerialPortError serialPortError) { if (serialPortError == QSerialPort::ReadError) { - m_standardOutput << QObject::tr("An I/O error occurred while reading the data from port %1, error: %2").arg(m_serialPort->portName()).arg(m_serialPort->errorString()) << endl; + m_standardOutput << QObject::tr("An I/O error occurred while reading " + "the data from port %1, error: %2") + .arg(m_serialPort->portName()) + .arg(m_serialPort->errorString()) + << endl; QCoreApplication::exit(1); } } |