summaryrefslogtreecommitdiff
path: root/examples/serialport/creaderasync/serialportreader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/serialport/creaderasync/serialportreader.cpp')
-rw-r--r--examples/serialport/creaderasync/serialportreader.cpp32
1 files changed, 17 insertions, 15 deletions
diff --git a/examples/serialport/creaderasync/serialportreader.cpp b/examples/serialport/creaderasync/serialportreader.cpp
index f85dd8a..a701839 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);
}
}