Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to populate a combobox using a Qvector
Forum Updated to NodeBB v4.3 + New Features

How to populate a combobox using a Qvector

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.3k Views 1 Watching
  • 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.
  • L Offline
    L Offline
    lima_will
    wrote on 16 Sept 2013, 13:19 last edited by
    #1

    Guys,

    I need again your help, I need to populate a combobox using a vector.
    I have a screen where the User enters the data, these data are stored in a Qvector.
    Now I need to populate a combobox with the data that Qvector.
    Below is the code fill the Qvector:

    @QString IP;
    QTextCharFormat textFormat;
    IP = ui->Campo_Digitar_ip->text();
    IP += "\n";
    QTextCursor cursor(ui->textEdit->textCursor());
    cursor.insertText(IP);
    vetorIP.append(IP);@

    And as I have tried so far to fill the combobox

    @while(vetorIP.operator !=(0))
    {
    ui->comboBox_IP_Cadastro->addItem(vetorIP);
    }@

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on 16 Sept 2013, 13:40 last edited by
      #2

      You can populate a combobox using "addItems":http://qt-project.org/doc/qt-5.0/qtwidgets/qcombobox.html#addItems which requires a "QStringList.":http://qt-project.org/doc/qt-5.0/qtcore/qstringlist.html
      QStringList can be generated by "toList.":http://qt-project.org/doc/qt-5.0/qtcore/qvector.html#toList

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 16 Sept 2013, 13:43 last edited by
        #3

        Hi,

        You should rather use something like:

        @
        foreach (const QString& ip, vectorIP) {
        ui->comboBox_IP_Cadastro->addItem(ip);
        }
        @

        Hope it helps

        EDIT: koahnig's solution is even more elegant

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lima_will
          wrote on 18 Sept 2013, 14:09 last edited by
          #4

          Guys,

          I appreciate the help I ended up studying the documentation I saw that it was easier to fill the combobox with a QStringList.

          I only have a problem in making information appear in another Dialog, the first screen have a combobox and a button to enter the "IPS", after that I have a screen to add the "IPS".

          I just can not get the screen information for inclusion in the main screen, attached is an example of the code.

          It would be possible to show me where I'm wrong?

          https://docs.google.com/file/d/0BwQ4G9j5uY1JUzdfSFlrYTV5V2s/edit?usp=sharing

          1 Reply Last reply
          0

          1/4

          16 Sept 2013, 13:19

          • Login

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