Update combobox data from model
Solved
General and Desktop
-
I have a categories QComboBox which is linked to a QSqlTableModel. Also I have a second window to manage categories (add/remove). How to update/refresh/reload the combobox whenever a category is added/removed?
My code:
int catIndex = model2->fieldIndex("category"); model2->setRelation(catIndex, QSqlRelation("categories", "id", "name")); QSqlTableModel *catModel = model2->relationModel(catIndex); ui->comboBox_2->setModel(catModel); ui->comboBox_2->setModelColumn(catModel->fieldIndex("name")); mapper->addMapping(ui->comboBox_2, catIndex);
-
Hi,
How are you adding / removing these categories ?
-
Hi @rudag
I do not understand. You wrote the code in your first post. Just call it again. Then the changed model should refill the combobox.
If you want the model to update your combobox, though, you will probably have to derive your own model class and override the functions for update and remove of data sets.
-Michael.
-
Then why not share the model between the widgets ?