How to insert item to combobox that uses a QSQLquery model
-
Hello guys
I have Combobox and SQLite. I read the database and load the data into the combobox. How can I add data to this combobox that does not exist in the database?
@
model->setQuery(query);
ui->logindBList->setModel(model);I want to add this item to the list of data in the combo but it does not work
ui->logindBList->addItem("localhost");
@ -
No, that does not work. It is either/or. Either you use an editable model like the default model, or you use an SQL query model. An SQL query model is not editable, so you cannot add items to it. You might try if it works with an QSqlTableModel instead, but I doubt it. Instead, you could read-in the data from the query, and add this data as items in your combobox. That will allow you to add new items, that you can then add back to the database.
-
Thank you for your reply, but i dont know how to read the data from the modelquery
do you have an example? -
I don't want to use QSQLQuery. Is there a way to copy the model into another editable model?
-
I found this link which describes it. Thank you Andre