summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-05-20 19:31:55 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-05-20 19:31:55 +0200
commit5110f89b2bb1ca22b9f2bd254287696636082332 (patch)
treeb20b5c97a7a38339af134b1ba8ff4729b54877ce
parentadd8cb835b7e519955f1260244f7033b049d4930 (diff)
parent9e8daaed0466d760e047c5da58811e55e7807c0a (diff)
downloadqtserialport-5110f89b2bb1ca22b9f2bd254287696636082332.tar.gz
Merge 5.7 into 5.7.0
Change-Id: I2e0737fab1c12657d8dc7de5d1882ecb73bbb5f2
-rw-r--r--examples/serialport/blockingmaster/blockingmaster.pro3
-rw-r--r--examples/serialport/blockingmaster/dialog.cpp3
-rw-r--r--examples/serialport/blockingslave/blockingslave.pro3
-rw-r--r--examples/serialport/blockingslave/dialog.cpp3
-rw-r--r--examples/serialport/cenumerator/cenumerator.pro3
-rw-r--r--examples/serialport/cenumerator/main.cpp6
-rw-r--r--examples/serialport/creaderasync/creaderasync.pro3
-rw-r--r--examples/serialport/creadersync/creadersync.pro3
-rw-r--r--examples/serialport/cwriterasync/cwriterasync.pro3
-rw-r--r--examples/serialport/cwritersync/cwritersync.pro3
-rw-r--r--examples/serialport/enumerator/enumerator.pro3
-rw-r--r--examples/serialport/enumerator/main.cpp3
-rw-r--r--examples/serialport/master/master.pro3
-rw-r--r--examples/serialport/serialport.pro3
-rw-r--r--examples/serialport/slave/slave.pro3
-rw-r--r--examples/serialport/terminal/settingsdialog.cpp3
-rw-r--r--examples/serialport/terminal/terminal.pro3
-rw-r--r--src/serialport/doc/qtserialport.qdocconf2
-rw-r--r--src/serialport/qserialport_p.h2
-rw-r--r--src/serialport/qserialport_unix.cpp16
-rw-r--r--src/serialport/qserialport_win.cpp29
-rw-r--r--src/serialport/qserialportinfo.cpp14
-rw-r--r--src/serialport/qserialportinfo_freebsd.cpp15
-rw-r--r--src/serialport/qserialportinfo_unix.cpp11
-rw-r--r--src/serialport/qserialportinfo_win.cpp7
-rw-r--r--tests/auto/qserialport/tst_qserialport.cpp8
26 files changed, 104 insertions, 54 deletions
diff --git a/examples/serialport/blockingmaster/blockingmaster.pro b/examples/serialport/blockingmaster/blockingmaster.pro
index 8f3e0a1..7cf76d8 100644
--- a/examples/serialport/blockingmaster/blockingmaster.pro
+++ b/examples/serialport/blockingmaster/blockingmaster.pro
@@ -11,3 +11,6 @@ SOURCES += \
main.cpp \
dialog.cpp \
masterthread.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/blockingmaster
+INSTALLS += target
diff --git a/examples/serialport/blockingmaster/dialog.cpp b/examples/serialport/blockingmaster/dialog.cpp
index 8101424..c1ca850 100644
--- a/examples/serialport/blockingmaster/dialog.cpp
+++ b/examples/serialport/blockingmaster/dialog.cpp
@@ -74,7 +74,8 @@ Dialog::Dialog(QWidget *parent)
, statusLabel(new QLabel(tr("Status: Not running.")))
, runButton(new QPushButton(tr("Start")))
{
- foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos)
serialPortComboBox->addItem(info.portName());
waitResponseSpinBox->setRange(0, 10000);
diff --git a/examples/serialport/blockingslave/blockingslave.pro b/examples/serialport/blockingslave/blockingslave.pro
index 2477b52..11b9b80 100644
--- a/examples/serialport/blockingslave/blockingslave.pro
+++ b/examples/serialport/blockingslave/blockingslave.pro
@@ -11,3 +11,6 @@ SOURCES += \
main.cpp \
dialog.cpp \
slavethread.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/blockingslave
+INSTALLS += target
diff --git a/examples/serialport/blockingslave/dialog.cpp b/examples/serialport/blockingslave/dialog.cpp
index 3cef0cf..8550773 100644
--- a/examples/serialport/blockingslave/dialog.cpp
+++ b/examples/serialport/blockingslave/dialog.cpp
@@ -77,7 +77,8 @@ Dialog::Dialog(QWidget *parent)
waitRequestSpinBox->setRange(0, 10000);
waitRequestSpinBox->setValue(10000);
- foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos)
serialPortComboBox->addItem(info.portName());
QGridLayout *mainLayout = new QGridLayout;
diff --git a/examples/serialport/cenumerator/cenumerator.pro b/examples/serialport/cenumerator/cenumerator.pro
index f5494fd..75a43e3 100644
--- a/examples/serialport/cenumerator/cenumerator.pro
+++ b/examples/serialport/cenumerator/cenumerator.pro
@@ -9,3 +9,6 @@ TEMPLATE = app
SOURCES += \
main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cenumerator
+INSTALLS += target
diff --git a/examples/serialport/cenumerator/main.cpp b/examples/serialport/cenumerator/main.cpp
index 7166b0b..f805021 100644
--- a/examples/serialport/cenumerator/main.cpp
+++ b/examples/serialport/cenumerator/main.cpp
@@ -58,16 +58,16 @@ int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTextStream out(stdout);
- QList<QSerialPortInfo> serialPortInfoList = QSerialPortInfo::availablePorts();
+ const auto serialPortInfos = QSerialPortInfo::availablePorts();
- out << QObject::tr("Total number of ports available: ") << serialPortInfoList.count() << endl;
+ out << QObject::tr("Total number of ports available: ") << serialPortInfos.count() << endl;
const QString blankString = QObject::tr("N/A");
QString description;
QString manufacturer;
QString serialNumber;
- foreach (const QSerialPortInfo &serialPortInfo, serialPortInfoList) {
+ for (const QSerialPortInfo &serialPortInfo : serialPortInfos) {
description = serialPortInfo.description();
manufacturer = serialPortInfo.manufacturer();
serialNumber = serialPortInfo.serialNumber();
diff --git a/examples/serialport/creaderasync/creaderasync.pro b/examples/serialport/creaderasync/creaderasync.pro
index 3565dc9..38d8b52 100644
--- a/examples/serialport/creaderasync/creaderasync.pro
+++ b/examples/serialport/creaderasync/creaderasync.pro
@@ -13,3 +13,6 @@ HEADERS += \
SOURCES += \
main.cpp \
serialportreader.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/creaderasync
+INSTALLS += target
diff --git a/examples/serialport/creadersync/creadersync.pro b/examples/serialport/creadersync/creadersync.pro
index ee9eaf2..a2690aa 100644
--- a/examples/serialport/creadersync/creadersync.pro
+++ b/examples/serialport/creadersync/creadersync.pro
@@ -9,3 +9,6 @@ TEMPLATE = app
SOURCES += \
main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/creadersync
+INSTALLS += target
diff --git a/examples/serialport/cwriterasync/cwriterasync.pro b/examples/serialport/cwriterasync/cwriterasync.pro
index 0945f1d..f6105bc 100644
--- a/examples/serialport/cwriterasync/cwriterasync.pro
+++ b/examples/serialport/cwriterasync/cwriterasync.pro
@@ -13,3 +13,6 @@ HEADERS += \
SOURCES += \
main.cpp \
serialportwriter.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cwriterasync
+INSTALLS += target
diff --git a/examples/serialport/cwritersync/cwritersync.pro b/examples/serialport/cwritersync/cwritersync.pro
index 08f50a2..1e0996d 100644
--- a/examples/serialport/cwritersync/cwritersync.pro
+++ b/examples/serialport/cwritersync/cwritersync.pro
@@ -9,3 +9,6 @@ TEMPLATE = app
SOURCES += \
main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/cwritersync
+INSTALLS += target
diff --git a/examples/serialport/enumerator/enumerator.pro b/examples/serialport/enumerator/enumerator.pro
index 9819fd7..3989335 100644
--- a/examples/serialport/enumerator/enumerator.pro
+++ b/examples/serialport/enumerator/enumerator.pro
@@ -5,3 +5,6 @@ TEMPLATE = app
SOURCES += \
main.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/enumerator
+INSTALLS += target
diff --git a/examples/serialport/enumerator/main.cpp b/examples/serialport/enumerator/main.cpp
index a997bf5..fa925da 100644
--- a/examples/serialport/enumerator/main.cpp
+++ b/examples/serialport/enumerator/main.cpp
@@ -64,7 +64,8 @@ int main(int argc, char *argv[])
QVBoxLayout *layout = new QVBoxLayout;
- foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos) {
QString s = QObject::tr("Port: ") + info.portName() + "\n"
+ QObject::tr("Location: ") + info.systemLocation() + "\n"
+ QObject::tr("Description: ") + info.description() + "\n"
diff --git a/examples/serialport/master/master.pro b/examples/serialport/master/master.pro
index 977de6c..354d174 100644
--- a/examples/serialport/master/master.pro
+++ b/examples/serialport/master/master.pro
@@ -13,3 +13,6 @@ HEADERS += \
SOURCES += \
main.cpp \
dialog.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/master
+INSTALLS += target
diff --git a/examples/serialport/serialport.pro b/examples/serialport/serialport.pro
index c0e77df..6d00a22 100644
--- a/examples/serialport/serialport.pro
+++ b/examples/serialport/serialport.pro
@@ -1,4 +1,3 @@
TEMPLATE = subdirs
-CONFIG += ordered
SUBDIRS = cenumerator creaderasync creadersync cwriterasync cwritersync
-!isEmpty(QT.widgets.name):SUBDIRS += enumerator terminal blockingmaster blockingslave
+!isEmpty(QT.widgets.name):SUBDIRS += enumerator terminal blockingmaster blockingslave master slave
diff --git a/examples/serialport/slave/slave.pro b/examples/serialport/slave/slave.pro
index df996ac..54e7d02 100644
--- a/examples/serialport/slave/slave.pro
+++ b/examples/serialport/slave/slave.pro
@@ -13,3 +13,6 @@ HEADERS += \
SOURCES += \
main.cpp \
dialog.cpp
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/slave
+INSTALLS += target
diff --git a/examples/serialport/terminal/settingsdialog.cpp b/examples/serialport/terminal/settingsdialog.cpp
index ded4b18..f9b8605 100644
--- a/examples/serialport/terminal/settingsdialog.cpp
+++ b/examples/serialport/terminal/settingsdialog.cpp
@@ -171,7 +171,8 @@ void SettingsDialog::fillPortsInfo()
QString description;
QString manufacturer;
QString serialNumber;
- foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos) {
QStringList list;
description = info.description();
manufacturer = info.manufacturer();
diff --git a/examples/serialport/terminal/terminal.pro b/examples/serialport/terminal/terminal.pro
index 1e45e55..4dbed02 100644
--- a/examples/serialport/terminal/terminal.pro
+++ b/examples/serialport/terminal/terminal.pro
@@ -20,3 +20,6 @@ FORMS += \
RESOURCES += \
terminal.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/serialport/terminal
+INSTALLS += target
diff --git a/src/serialport/doc/qtserialport.qdocconf b/src/serialport/doc/qtserialport.qdocconf
index ac1fc1e..78c1b35 100644
--- a/src/serialport/doc/qtserialport.qdocconf
+++ b/src/serialport/doc/qtserialport.qdocconf
@@ -34,7 +34,7 @@ exampledirs += ../../../examples/serialport
imagedirs += images
excludedirs += ../qt4support
-examplesinstallpath = qtserialport/serialport
+examplesinstallpath = serialport
depends += qtcore qtdoc qtnetwork qmake
diff --git a/src/serialport/qserialport_p.h b/src/serialport/qserialport_p.h
index ae2089d..cb300ad 100644
--- a/src/serialport/qserialport_p.h
+++ b/src/serialport/qserialport_p.h
@@ -188,6 +188,8 @@ public:
bool getDcb(DCB *dcb);
OVERLAPPED *waitForNotified(int msecs);
+ qint64 queuedBytesCount(QSerialPort::Direction direction) const;
+
bool completeAsyncCommunication(qint64 bytesTransferred);
bool completeAsyncRead(qint64 bytesTransferred);
bool completeAsyncWrite(qint64 bytesTransferred);
diff --git a/src/serialport/qserialport_unix.cpp b/src/serialport/qserialport_unix.cpp
index d830085..7078040 100644
--- a/src/serialport/qserialport_unix.cpp
+++ b/src/serialport/qserialport_unix.cpp
@@ -125,7 +125,7 @@ QString serialPortLockFilePath(const QString &portName)
QString lockFilePath;
- foreach (const QString &lockDirectoryPath, lockDirectoryPaths) {
+ for (const QString &lockDirectoryPath : lockDirectoryPaths) {
const QString filePath = lockDirectoryPath + fileName;
QFileInfo lockDirectoryInfo(lockDirectoryPath);
@@ -139,7 +139,7 @@ QString serialPortLockFilePath(const QString &portName)
if (lockFilePath.isEmpty()) {
qWarning("The following directories are not readable or writable for detaling with lock files\n");
- foreach (const QString &lockDirectoryPath, lockDirectoryPaths)
+ for (const QString &lockDirectoryPath : lockDirectoryPaths)
qWarning("\t%s\n", qPrintable(lockDirectoryPath));
return QString();
}
@@ -250,15 +250,11 @@ void QSerialPortPrivate::close()
::ioctl(descriptor, TIOCNXCL);
#endif
- if (readNotifier) {
- delete readNotifier;
- readNotifier = Q_NULLPTR;
- }
+ delete readNotifier;
+ readNotifier = Q_NULLPTR;
- if (writeNotifier) {
- delete writeNotifier;
- writeNotifier = Q_NULLPTR;
- }
+ delete writeNotifier;
+ writeNotifier = Q_NULLPTR;
qt_safe_close(descriptor);
diff --git a/src/serialport/qserialport_win.cpp b/src/serialport/qserialport_win.cpp
index 762deba..412e20c 100644
--- a/src/serialport/qserialport_win.cpp
+++ b/src/serialport/qserialport_win.cpp
@@ -112,15 +112,11 @@ void QSerialPortPrivate::close()
{
::CancelIo(handle);
- if (notifier) {
- delete notifier;
- notifier = Q_NULLPTR;
- }
+ delete notifier;
+ notifier = Q_NULLPTR;
- if (startAsyncWriteTimer) {
- delete startAsyncWriteTimer;
- startAsyncWriteTimer = Q_NULLPTR;
- }
+ delete startAsyncWriteTimer;
+ startAsyncWriteTimer = Q_NULLPTR;
communicationStarted = false;
readStarted = false;
@@ -443,10 +439,13 @@ bool QSerialPortPrivate::completeAsyncRead(qint64 bytesTransferred)
readStarted = false;
bool result = true;
- if (bytesTransferred == ReadChunkSize)
+ if (bytesTransferred == ReadChunkSize
+ || queuedBytesCount(QSerialPort::Input) > 0) {
result = startAsyncRead();
- else if (readBufferMaxSize == 0 || readBufferMaxSize > buffer.size())
+ } else if (readBufferMaxSize == 0
+ || readBufferMaxSize > buffer.size()) {
result = startAsyncCommunication();
+ }
if (bytesTransferred > 0)
emitReadyRead();
@@ -604,6 +603,16 @@ OVERLAPPED *QSerialPortPrivate::waitForNotified(int msecs)
return overlapped;
}
+qint64 QSerialPortPrivate::queuedBytesCount(QSerialPort::Direction direction) const
+{
+ COMSTAT comstat;
+ if (::ClearCommError(handle, Q_NULLPTR, &comstat) == 0)
+ return -1;
+ return (direction == QSerialPort::Input)
+ ? comstat.cbInQue
+ : ((direction == QSerialPort::Output) ? comstat.cbOutQue : -1);
+}
+
inline bool QSerialPortPrivate::initialize()
{
Q_Q(QSerialPort);
diff --git a/src/serialport/qserialportinfo.cpp b/src/serialport/qserialportinfo.cpp
index 76c18da..acd0179 100644
--- a/src/serialport/qserialportinfo.cpp
+++ b/src/serialport/qserialportinfo.cpp
@@ -88,9 +88,10 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPortInfo &other)
*/
QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
{
- foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) {
- if (port.portName() == serialPortInfo.portName()) {
- *this = serialPortInfo;
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos) {
+ if (port.portName() == info.portName()) {
+ *this = info;
break;
}
}
@@ -105,9 +106,10 @@ QSerialPortInfo::QSerialPortInfo(const QSerialPort &port)
*/
QSerialPortInfo::QSerialPortInfo(const QString &name)
{
- foreach (const QSerialPortInfo &serialPortInfo, availablePorts()) {
- if (name == serialPortInfo.portName()) {
- *this = serialPortInfo;
+ const auto infos = QSerialPortInfo::availablePorts();
+ for (const QSerialPortInfo &info : infos) {
+ if (name == info.portName()) {
+ *this = info;
break;
}
}
diff --git a/src/serialport/qserialportinfo_freebsd.cpp b/src/serialport/qserialportinfo_freebsd.cpp
index f3bf92e..291cfac 100644
--- a/src/serialport/qserialportinfo_freebsd.cpp
+++ b/src/serialport/qserialportinfo_freebsd.cpp
@@ -122,7 +122,7 @@ static QVector<int> nextOid(const QVector<int> &previousOid)
QVector<int> mib;
mib.append(0); // Magic undocumented code (CTL_UNSPEC ?)
mib.append(2); // Magic undocumented code
- foreach (int code, previousOid)
+ for (int code : previousOid)
mib.append(code);
size_t requiredLength = 0;
@@ -144,7 +144,7 @@ static NodeInfo nodeForOid(const QVector<int> &oid)
QVector<int> mib;
mib.append(0); // Magic undocumented code (CTL_UNSPEC ?)
mib.append(1); // Magic undocumented code
- foreach (int code, oid)
+ for (int code : oid)
mib.append(code);
// query node name
@@ -234,7 +234,8 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QList<QSerialPortInfo> cuaCandidates;
QList<QSerialPortInfo> ttyCandidates;
- foreach (const QString &portName, deviceDir.entryList()) {
+ const auto portNames = deviceDir.entryList();
+ for (const QString &portName : portNames) {
if (portName.endsWith(QLatin1String(".init"))
|| portName.endsWith(QLatin1String(".lock"))) {
continue;
@@ -244,7 +245,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
priv.portName = portName;
priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName);
- foreach (const NodeInfo &node, nodes) {
+ for (const NodeInfo &node : nodes) {
const int pnpinfoindex = node.name.indexOf(QLatin1String("\%pnpinfo"));
if (pnpinfoindex == -1)
continue;
@@ -288,7 +289,7 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
const QString descnode = QString(QLatin1String("%1\%desc")).arg(nodebase);
// search for description and manufacturer properties
- foreach (const NodeInfo &node, nodes) {
+ for (const NodeInfo &node : nodes) {
if (node.name != descnode)
continue;
@@ -313,10 +314,10 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
QList<QSerialPortInfo> serialPortInfoList;
- foreach (const QSerialPortInfo &cuaCandidate, cuaCandidates) {
+ for (const QSerialPortInfo &cuaCandidate : qAsConst(cuaCandidates)) {
const QString cuaPortName = cuaCandidate.portName();
const QString cuaToken = deviceProperty(cuaPortName, "cua");
- foreach (const QSerialPortInfo &ttyCandidate, ttyCandidates) {
+ for (const QSerialPortInfo &ttyCandidate : qAsConst(ttyCandidates)) {
const QString ttyPortName = ttyCandidate.portName();
const QString ttyToken = deviceProperty(ttyPortName, "tty");
if (cuaToken != ttyToken)
diff --git a/src/serialport/qserialportinfo_unix.cpp b/src/serialport/qserialportinfo_unix.cpp
index a93ac05..08e75c1 100644
--- a/src/serialport/qserialportinfo_unix.cpp
+++ b/src/serialport/qserialportinfo_unix.cpp
@@ -90,7 +90,8 @@ static QStringList filteredDeviceFilePaths()
deviceDir.setNameFilters(deviceFileNameFilterList);
deviceDir.setFilter(QDir::Files | QDir::System | QDir::NoSymLinks);
QStringList deviceFilePaths;
- foreach (const QFileInfo &deviceFileInfo, deviceDir.entryInfoList()) {
+ const auto deviceFileInfos = deviceDir.entryInfoList();
+ for (const QFileInfo &deviceFileInfo : deviceFileInfos) {
const QString deviceAbsoluteFilePath = deviceFileInfo.absoluteFilePath();
#ifdef Q_OS_FREEBSD
@@ -115,7 +116,8 @@ QList<QSerialPortInfo> availablePortsByFiltersOfDevices(bool &ok)
{
QList<QSerialPortInfo> serialPortInfoList;
- foreach (const QString &deviceFilePath, filteredDeviceFilePaths()) {
+ const auto deviceFilePaths = filteredDeviceFilePaths();
+ for (const QString &deviceFilePath : deviceFilePaths) {
QSerialPortInfoPrivate priv;
priv.device = deviceFilePath;
priv.portName = QSerialPortInfoPrivate::portNameFromSystemLocation(deviceFilePath);
@@ -155,7 +157,7 @@ static bool isRfcommDevice(const QString &portName)
return false;
bool ok;
- const int portNumber = portName.mid(6).toInt(&ok);
+ const int portNumber = portName.midRef(6).toInt(&ok);
if (!ok || (portNumber < 0) || (portNumber > 255))
return false;
return true;
@@ -250,7 +252,8 @@ QList<QSerialPortInfo> availablePortsBySysfs(bool &ok)
QList<QSerialPortInfo> serialPortInfoList;
ttySysClassDir.setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
- foreach (const QFileInfo &fileInfo, ttySysClassDir.entryInfoList()) {
+ const auto fileInfos = ttySysClassDir.entryInfoList();
+ for (const QFileInfo &fileInfo : fileInfos) {
if (!fileInfo.isSymLink())
continue;
diff --git a/src/serialport/qserialportinfo_win.cpp b/src/serialport/qserialportinfo_win.cpp
index bb9b18f..995f1d7 100644
--- a/src/serialport/qserialportinfo_win.cpp
+++ b/src/serialport/qserialportinfo_win.cpp
@@ -344,9 +344,10 @@ QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
::SetupDiDestroyDeviceInfoList(deviceInfoSet);
}
- foreach (const QString &portName, portNamesFromHardwareDeviceMap()) {
- if (std::find_if(serialPortInfoList.begin(), serialPortInfoList.end(),
- SerialPortNameEqualFunctor(portName)) == serialPortInfoList.end()) {
+ const auto portNames = portNamesFromHardwareDeviceMap();
+ for (const QString &portName : portNames) {
+ if (std::find_if(serialPortInfoList.cbegin(), serialPortInfoList.cend(),
+ SerialPortNameEqualFunctor(portName)) == serialPortInfoList.cend()) {
QSerialPortInfoPrivate priv;
priv.portName = portName;
priv.device = QSerialPortInfoPrivate::portNameToSystemLocation(portName);
diff --git a/tests/auto/qserialport/tst_qserialport.cpp b/tests/auto/qserialport/tst_qserialport.cpp
index f100d35..b9d41b8 100644
--- a/tests/auto/qserialport/tst_qserialport.cpp
+++ b/tests/auto/qserialport/tst_qserialport.cpp
@@ -265,7 +265,7 @@ void tst_QSerialPort::openExisting()
QFETCH(bool, openResult);
QFETCH(QSerialPort::SerialPortError, errorCode);
- foreach (const QString &serialPortName, m_availablePortNames) {
+ for (const QString &serialPortName : qAsConst(m_availablePortNames)) {
QSerialPort serialPort(serialPortName);
QSignalSpy errorSpy(&serialPort, static_cast<void (QSerialPort::*)(QSerialPort::SerialPortError)>(&QSerialPort::error));
QVERIFY(errorSpy.isValid());
@@ -1055,9 +1055,9 @@ void tst_QSerialPort::controlBreak()
QVERIFY2(!timeout(), "Timed out when waiting for the read of break state.");
QVERIFY(receiverPort.bytesAvailable() > 0);
- foreach (const char c, receiverPort.readAll()) {
- QCOMPARE(c, char(0));
- }
+ const QByteArray actual = receiverPort.readAll();
+ const QByteArray expected(actual.size(), '\0');
+ QCOMPARE(actual, expected);
QVERIFY(senderPort.setBreakEnabled(false));
QCOMPARE(senderPort.isBreakEnabled(), false);