QComboBox - Select no entry
I have a QComboBox on my ui and set the model like this:
QStringListModel* model = new QStringListModel; QStringList stringlist; stringlist << "Test1" << "Test2" << "Test3"; model->setStringList(stringlist); ui->comboBox->setModel(model);
Now I want to change the current index to be none (so that I get a blank combo box).
I already tried setting the current index to -1 with
But that results to an index aout of range exeption in qlist:
ASSERT failure in QList<T>::operator: "index out of range", file F:/Qt/5.4/mingw491_32/include/QtCore/qlist.h, line 486
I not sure but i think thats your model fault. Looks like you since you want to use your own model you have to specify what to do with -1 index, couse it seems it is not implemented by default. Im guessing you really have to use custom
QStringListModelbut for such trivial use why just use default
QComboBoxand add items by
QComboBox::addItems(stringlist)? (just a sugestion)
Hi and welcome to devnet,
AFAIK, you need to have that blank element as part of your data or implement your own model to handle that use case.