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 predefine items in vector of qcombobox
Forum Updated to NodeBB v4.3 + New Features

how to predefine items in vector of qcombobox

Scheduled Pinned Locked Moved Solved General and Desktop
qt5.6comboboxvector
2 Posts 2 Posters 1.2k 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.
  • V Offline
    V Offline
    vasu_gupta
    wrote on 5 Sept 2017, 09:57 last edited by
    #1

    i have created a vector of combobox like this:

    QVector<QComboBox *> dbox1;
    

    now i want that when ever i add a new comboxox in this vector:

    dbox1.push_back(new QComboBox);
    

    i want that that particular combobox shall some items pre-entered

    dbox1[row_cnt]->addItem(QString("defect 1"));
    dbox1[row_cnt]->addItem(QString("defect 2"));
    dbox1[row_cnt]->addItem(QString("defect 3"));
    dbox1[row_cnt]->addItem(QString("defect 4"));
    dbox1[row_cnt]->addItem(QString("defect 5"));
    

    how to do so

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 5 Sept 2017, 10:01 last edited by
      #2

      Hi
      Just create a function and use that instead of new directly

      
      QComboBox * MakeDefaultCB(QObject *Parent) {
      QComboBox * cur= new QComboBox (Parent);
      cur->addItem(QString("defect 1"));
      cur->addItem(QString("defect 2"));
      ...
      return cur;
      }
      
      dbox1.push_back(MakeDefaultCB(this));
      
      1 Reply Last reply
      4

      2/2

      5 Sept 2017, 10:01

      • Login

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