0

How can i get the serial port list in the sub menu from the qt menuBar()

Select Port| debug | help
  |           
list comports -com1
               com2
               com3 

some part of my code

def Menu(self, event):  
    menubar = self.menuBar()
    fileMenu = menubar.addMenu('&Select Port')
    fileMenu.addAction(self.conn2)

def createActions(self):
    self.conn2 = QtGui.QAction(QtGui.QIcon('./some_image.png'),"&Connect", self,
                                  statusTip="Sellect ur com port", triggered=self.connect)

i need to get the list of available com ports in the sub menu of the Select Port tab or open a new dialog box with serial Ports listed

user2345
  • 537
  • 1
  • 5
  • 22

1 Answers1

0

Basically iterate through a list of available ports and add them as a kind of radio button checkable actions or as a QComboBox. Then when one gets selected, change your self.portName to reflect the new one.

The example in pure Qt for doing this is under the Terminal Qt Serial Port example, under the 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);
    }
}

It doesn't look like PyQt has the QtSerialPort library (probably because pySerial and similar libraries are already available).

Hope that helps.

phyatt
  • 18,472
  • 5
  • 61
  • 80