how to predefine items in vector of qcombobox



  • 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


  • Qt Champions 2016

    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));
    

Log in to reply
 

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