summaryrefslogtreecommitdiff
path: root/src/serialport/qserialport.cpp
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2015-08-27 12:26:01 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2015-08-28 13:53:54 +0000
commit2610d81ead1fc755606e2bcd1418235bc0051d80 (patch)
treeecb50ad909f02b8ac2cb6b23c0fe740c8cc2777b /src/serialport/qserialport.cpp
parent462f074efbf6ac2cf03b818fa4103f5529be0291 (diff)
downloadqtserialport-2610d81ead1fc755606e2bcd1418235bc0051d80.tar.gz
Unify common error strings in QSerialPortErrorInfo
Change-Id: I1275e80988274e2409455217d5ffb03014962604 Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com> Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'src/serialport/qserialport.cpp')
-rw-r--r--src/serialport/qserialport.cpp65
1 files changed, 55 insertions, 10 deletions
diff --git a/src/serialport/qserialport.cpp b/src/serialport/qserialport.cpp
index 74604b0..54a3f47 100644
--- a/src/serialport/qserialport.cpp
+++ b/src/serialport/qserialport.cpp
@@ -44,6 +44,51 @@
QT_BEGIN_NAMESPACE
+QSerialPortErrorInfo::QSerialPortErrorInfo(QSerialPort::SerialPortError newErrorCode,
+ const QString &newErrorString)
+ : errorCode(newErrorCode)
+ , errorString(newErrorString)
+{
+ if (errorString.isNull()) {
+ switch (errorCode) {
+ case QSerialPort::NoError:
+ errorString = QSerialPort::tr("No error");
+ break;
+ case QSerialPort::OpenError:
+ errorString = QSerialPort::tr("Device is already open");
+ break;
+ case QSerialPort::NotOpenError:
+ errorString = QSerialPort::tr("Device is not open");
+ break;
+ case QSerialPort::TimeoutError:
+ errorString = QSerialPort::tr("Operation timed out");
+ break;
+ case QSerialPort::ParityError:
+ errorString = QSerialPort::tr("Parity error detected while reading");
+ break;
+ case QSerialPort::BreakConditionError:
+ errorString = QSerialPort::tr("Break condition detected while reading");
+ break;
+ case QSerialPort::FramingError:
+ errorString = QSerialPort::tr("Framing error detected while reading");
+ break;
+ case QSerialPort::ReadError:
+ errorString = QSerialPort::tr("Error reading from device");
+ break;
+ case QSerialPort::WriteError:
+ errorString = QSerialPort::tr("Error writing to device");
+ break;
+ case QSerialPort::ResourceError:
+ errorString = QSerialPort::tr("Device disappeared from the system");
+ break;
+ default:
+ // an empty string will be interpreted as "Unknown error"
+ // from the QIODevice::errorString()
+ break;
+ }
+ }
+}
+
QSerialPortPrivate::QSerialPortPrivate()
: readBufferMaxSize(0)
, writeBuffer(InitialBufferSize)
@@ -522,7 +567,7 @@ bool QSerialPort::open(OpenMode mode)
Q_D(QSerialPort);
if (isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::OpenError, tr("Device is already open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::OpenError));
return false;
}
@@ -562,7 +607,7 @@ void QSerialPort::close()
{
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
return;
}
@@ -875,7 +920,7 @@ bool QSerialPort::setDataTerminalReady(bool set)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -922,7 +967,7 @@ bool QSerialPort::setRequestToSend(bool set)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -972,7 +1017,7 @@ QSerialPort::PinoutSignals QSerialPort::pinoutSignals()
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return QSerialPort::NoSignal;
}
@@ -1002,7 +1047,7 @@ bool QSerialPort::flush()
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1024,7 +1069,7 @@ bool QSerialPort::clear(Directions directions)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1086,7 +1131,7 @@ bool QSerialPort::setDataErrorPolicy(DataErrorPolicy policy)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1312,7 +1357,7 @@ bool QSerialPort::sendBreak(int duration)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}
@@ -1342,7 +1387,7 @@ bool QSerialPort::setBreakEnabled(bool set)
Q_D(QSerialPort);
if (!isOpen()) {
- d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError, tr("Device is not open")));
+ d->setError(QSerialPortErrorInfo(QSerialPort::NotOpenError));
qWarning("%s: device not open", Q_FUNC_INFO);
return false;
}