From 89bc0b13f2a5363fc08fff750ffb53a929ef54f7 Mon Sep 17 00:00:00 2001 From: Philippe Renon Date: Mon, 14 Jul 2014 20:03:19 +0200 Subject: [PATCH] OP-1398 OP-1399 Windows Qt 5.3.1 upgrade - workaround for QSerialPortInfo::availablePorts() returning spurious ports (QTBUG-39748) --- .../plugins/serialconnection/serialplugin.cpp | 21 +++++++++++++++++-- .../plugins/serialconnection/serialplugin.h | 2 ++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp index 59d130c02..408e46773 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.cpp @@ -114,12 +114,29 @@ bool sortPorts(const QSerialPortInfo &s1, const QSerialPortInfo &s2) return s1.portName() < s2.portName(); } +QList SerialConnection::availablePorts() +{ + QList ports = QSerialPortInfo::availablePorts(); +#if QT_VERSION == 0x050301 && defined(Q_OS_WIN) + // workaround to QTBUG-39748 (https://bugreports.qt-project.org/browse/QTBUG-39748) + // Qt 5.3.1 reports spurious ports with an empty description... + QMutableListIterator i(ports); + while (i.hasNext()) { + if (i.next().description().isEmpty()) { + i.remove(); + } + } +#endif + return ports; +} + + QList SerialConnection::availableDevices() { QList list; if (enablePolling) { - QList ports = QSerialPortInfo::availablePorts(); + QList ports = availablePorts(); // sort the list by port number (nice idea from PT_Dreamer :)) qSort(ports.begin(), ports.end(), sortPorts); @@ -140,7 +157,7 @@ QIODevice *SerialConnection::openDevice(const QString &deviceName) if (serialHandle) { closeDevice(deviceName); } - QList ports = QSerialPortInfo::availablePorts(); + QList ports = availablePorts(); foreach(QSerialPortInfo port, ports) { if (port.portName() == deviceName) { // we need to handle port settings here... diff --git a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h index 14031a871..75385cea4 100644 --- a/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h +++ b/ground/openpilotgcs/src/plugins/serialconnection/serialplugin.h @@ -106,6 +106,8 @@ private: SerialPluginConfiguration *m_config; SerialPluginOptionsPage *m_optionspage; + QList availablePorts(); + protected slots: void onEnumerationChanged();