Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


  • Lifetime Qt Champion

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