2024-09-25 10:34:55 发布
网友
如何从qtmenuBar()子菜单中获取串行端口列表
menuBar()
Select Port| debug | help | list comports -com1 com2 com3
我代码的一部分
我需要在“选择端口”选项卡的子菜单中获取可用com端口的列表,或者打开一个列出串行端口的新对话框
基本上遍历一个可用端口的列表,并将它们作为一种单选按钮可检查操作或作为QComboBox添加。然后,当一个被选中时,更改您的self.portName以反映新的。在
QComboBox
self.portName
pure Qt中用于执行此操作的示例位于终端Qt串行端口示例下的SettingsDialog。在
SettingsDialog
http://doc.qt.io/qt-5/qtserialport-terminal-settingsdialog-cpp.html
void SettingsDialog::fillPortsInfo() { ui->serialPortInfoListBox->clear(); static const QString blankString = QObject::tr("N/A"); QString description; QString manufacturer; QString serialNumber; foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) { QStringList list; description = info.description(); manufacturer = info.manufacturer(); serialNumber = info.serialNumber(); list << info.portName() << (!description.isEmpty() ? description : blankString) << (!manufacturer.isEmpty() ? manufacturer : blankString) << (!serialNumber.isEmpty() ? serialNumber : blankString) << info.systemLocation() << (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : blankString) << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : blankString); ui->serialPortInfoListBox->addItem(list.first(), list); } }
看起来PyQt没有QtSerialPort库(可能是因为pySerial和类似的库已经可用)。在
PyQt
QtSerialPort
pySerial
希望有帮助。在
基本上遍历一个可用端口的列表,并将它们作为一种单选按钮可检查操作或作为
QComboBox
添加。然后,当一个被选中时,更改您的self.portName
以反映新的。在pure Qt中用于执行此操作的示例位于终端Qt串行端口示例下的
SettingsDialog
。在http://doc.qt.io/qt-5/qtserialport-terminal-settingsdialog-cpp.html
看起来
PyQt
没有QtSerialPort
库(可能是因为pySerial
和类似的库已经可用)。在希望有帮助。在
相关问题 更多 >
编程相关推荐