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. Updating elements in model of Combobox from c++

Updating elements in model of Combobox from c++

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.2k 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.
  • P Offline
    P Offline
    Pamast
    wrote on last edited by
    #1

    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?

    GrecKoG 1 Reply Last reply
    0
    • P Pamast

      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?

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

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

      1 Reply Last reply
      1
      • P Offline
        P Offline
        Pamast
        wrote on last edited by
        #3

        That did the trick. Thank you!

        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