Qt: c++: how to fill QComboBox using QStringList
Use addItems or insertItems member function of QComboBox. //notice there is an s in the end for the functions that takes a QStringList argument: it's add/insert Items
LE: don't pass the address of your QStringList, the function takes a reference to a QStringList object, not a pointer, use: ui->QComboBox->insertItems(0, sequence_len); //no & before sequence_len
Complete example of filling QComboBox (considering that tr()
is properly setup):
QStringList sequence_len = QStringList() << tr("1") << tr("2") << tr("3") << tr("4") << tr("5");
//add items:
ui->QComboBox->addItems(sequence_len);
//insert items into the position you need
//ui->QComboBox->insertItems(0, sequence_len);
don't pass the sting list as pointer
ui->QComboBox->insertItem(0, sequence_len);
Try this:
//Text that you want to QStringList
QStringList list;
list << "a" << "b" << "c";
//Instance of model type to QStringList
QStringListModel *model = new QStringListModel();
model->setStringList(list);
ui->QComboBox->setModel(model);
In this case, QStringList list
can be your list in sequence_len
.