QCombobox doesn't select when changing currentIndex
In my constructor I connect to a Sqlite Database and read "Categories"
(QStrings) from it. I store them in a QList. I checked via debugger if
they're empty, but everything is fine.
The int currCategoryIndex is set to 0 in my initializer list. And since
QComboboxes start indexing from 0 it should be the first item.
An extract from my constructor:
dm.readDB_C(c_list); //reads into c_list
if(c_list.count() > 0) //has 1 or more items
updateCategories();
This is the part where I read the database, check if it's empty and if not
call a function which adds those categories to a QComboBox.
updateCategories() function :
void MainWindow::updateCategories()
{
for(int i = 0; i < c_list.count(); i++){
if(ui->cmbCategory->findText(c_list[i]) != -1){ //-1 means "not
found"
continue;
} else {
ui->cmbCategory->addItem(c_list[i]); //Add to QCombobox
}
}
ui->cmbCategory->setCurrentIndex(currCategoryIndex); //Should be the
first item
}
I have all items in my QCombobox but none is selected. I have to click the
box and select one myself. That's not supposed to happen.
What is wrong? Why doesn't it select one itself?
No comments:
Post a Comment