Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Add in qml combobox serial port name seach in C++

Add in qml combobox serial port name seach in C++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 910 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alou1984
    wrote on last edited by
    #1

    hello .
    I want to add in my combobox define in my qml file all serial port name available .
    Debug() function print correctely port names but combo box in app is empty..... please help...

    // C++
    int main(int argc, char *argv[])
    {
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;

    QQmlComponent component(&engine, QUrl(QLatin1String("qrc:/main.qml")));
    QObject *object = component.create();
    
    QStringList lport;
    QList<QSerialPortInfo> ListPort;
    ListPort = QSerialPortInfo::availablePorts();
    
    qDebug() << "Number of serial ports:" << ListPort.count();
    for (int i=0; i < ListPort.size();i++)
    {
        qDebug() << "Names of serial ports:" << ListPort.at(i).portName();
        lport << ListPort.at(i).portName();
    }
    QObject * ComboPort = object->findChild<QObject*>("cb_port");
    if (ComboPort)
     {
            ComboPort->setProperty("cbItems",lport);
     }
    return app.exec();
    

    }

    // Qml

    ComboBox {
    id: cb_port
    objectName: "cb_port"
    x: 480
    y: 91
    anchors.bottom: parent.bottom
    anchors.bottomMargin: 519
    model: cbItems
    }

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved