Updating elements in model of Combobox from c++



  • I have created a combobox in which I want to show all the serial ports from my computer.

    I update them through a button I have which calls a slot to fetch all ports in a QStringList (I just keep the port name).

    I want to show that list of ports in my combobox so I did something like:

    Q_PROPERTY(QStringList    comPortList   READ getCOMPorts      NOTIFY comPortsChanged)
    

    My combobox:

    ComboBox {
                                    id: comport_box
                                    currentIndex: 0
                                    textRole: "text"
                                    model:_managerInstance.comPortList
                                    width: 200
                                }
    

    It shows an updated list. If there are 5 ports, combobox has 5 rows, 4 ports, 4 rows... But all rows are empty. I cannot get the text on each row. I am pretty sure the QStringList has the text because I print with qDebug before passing it.

    Do I need to add something else to that combobox to update the text in each row?



  • Since your model is a QStringList, it doesn't have roles.
    Remove the textRole: "text" line and you should be fine.



  • That did the trick. Thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.