forked from CDUTOSA/ZFlash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportcombobox.cpp
More file actions
49 lines (43 loc) · 1.19 KB
/
Copy pathportcombobox.cpp
File metadata and controls
49 lines (43 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "portcombobox.h"
#include <QSerialPortInfo>
#include <QMessageBox>
#include <cstdlib>
PortComboBox::PortComboBox(QWidget *parent):
QComboBox(parent)
{
doPortScan();
}
PortComboBox::~PortComboBox()
{
}
QString PortComboBox::getCurrentPortName() const
{
return currentPortName;
}
/* 按下检测按钮执行,修改下拉栏内容 */
void PortComboBox::doPortScan()
{
reset();
int portNumber = 0;
portInfoList = QSerialPortInfo::availablePorts();
foreach (QSerialPortInfo portInfoTmp, portInfoList) {
currentPortName = portInfoTmp.portName();
bool ok;
portNumber = portInfoTmp.portName().remove(0, 3).toInt(&ok, 10);
if (!ok) {
QMessageBox::critical(this, "Error", "An internal error occurred!",
QMessageBox::Close);
exit(EXIT_FAILURE);
}
this->setItemText(portNumber, currentPortName
+ " (" + portInfoTmp.description() + ")");
}
setCurrentIndex(portNumber);
}
void PortComboBox::reset()
{
clear();
for (int i = 0; i < 32; i++) {
addItem("COM" + QString::number(i));
}
}