how to predefine items in vector of qcombobox
Solved
General and Desktop
-
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
-
Hi
Just create a function and use that instead of new directlyQComboBox * 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));