diff --git a/portcontrol.cpp b/portcontrol.cpp --- a/portcontrol.cpp +++ b/portcontrol.cpp @@ -42,6 +42,10 @@ PortControl::PortControl(QSerialPort* po SELECT::OVERLOAD_OF(&QComboBox::activated), this, &PortControl::selectPort); + QObject::connect(ui->cbPortList, + SELECT::OVERLOAD_OF(&QComboBox::activated), + this, &PortControl::onPortNameChanged); + QObject::connect(ui->cbBaudRate, SELECT::OVERLOAD_OF(&QComboBox::activated), this, &PortControl::selectBaudRate); @@ -105,11 +109,15 @@ void PortControl::loadPortList() ui->cbPortList->clear(); + discoveredPorts.clear(); for (auto port : QSerialPortInfo::availablePorts()) { ui->cbPortList->addItem(port.portName()); + discoveredPorts << port.portName(); } + ui->cbPortList->addItems(userEnteredPorts); + // find current selection in the new list, maybe it doesn't exist anymore? int currentSelectionIndex = ui->cbPortList->findText(currentSelection); if (currentSelectionIndex >= 0) @@ -245,3 +253,13 @@ void PortControl::enableSkipByte(bool en { ui->pbSkipByte->setDisabled(enabled); } + +void PortControl::onPortNameChanged(QString portName) +{ + // was this a user entered name? + if(!discoveredPorts.contains(portName) && + !userEnteredPorts.contains(portName)) + { + userEnteredPorts << portName; + } +}