Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to add options or items to QComboBox dynamically?
Qt 6.12 LTS is out! See what's new in the release blog

How to add options or items to QComboBox dynamically?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 3 Posters 4.1k 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.
  • S Offline
    S Offline
    Sherlin N G
    wrote on last edited by
    #1

    I have a Qcombobox in my ui.The number of options in the combobox should be dynamically added.
    I tried ui->comboBox->additem("one");
    ui->comboBox->additem("two");
    its not working.Please suggest

    jsulmJ 1 Reply Last reply
    0
    • Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by
      #2

      Hi,

      QComboBox has method addItems(), store the values which u are getting from database or file in QStringList variable, then pass the variable to addItems().

      Below is the sample lines of code :
      QStringList stringList;
      stringList // store the values in this variable

      QComboBox comboboxObject;
      comboboxObject.addItems(stringList);

      Thanks,

      Pradeep Kumar
      Qt,QML Developer

      1 Reply Last reply
      3
      • S Sherlin N G

        I have a Qcombobox in my ui.The number of options in the combobox should be dynamically added.
        I tried ui->comboBox->additem("one");
        ui->comboBox->additem("two");
        its not working.Please suggest

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Sherlin-N-G I just tried addItem and it works just fine.
        Can you show more of your code?
        You're definitely doing something wrong.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        2

        • Login

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