PDA

View Full Version : QComboBox refresh problem



waynew
19th April 2011, 01:51
I have 2 forms, a display form and an options form. You can call the options form from the display form and add or delete records from a database table. The display form has a combo box driven with a model from the database table managed from the options form.

The problem is that when you call the options form from the display form and add or delete a record, the combo box does not get updated, even though there is a signal emitted from the options form and debug statements in the display form slot that show that the number of items in the combo box has been corrected to match the database table. If you look at the database table with a diagnostic tool, it is correct.

If you close the display form and re-open it, it shows the correct values in the combo box, but not if you don't close and re-open it.

I can provide snippets of code if necessary, but yes, the display form slot is public and with debug, you can see the signal is emitted and received in the slot and the database has been updated and the combo box does have the correct values in the slot, but the combo box display just doesn't get updated to show the changes unless you close and re-open the form.

Someone else must have had this problem before and solved it, but I can't find a similar case in the archives.

Any ideas? And tnx for any help.

jmeb2206
19th April 2011, 03:33
You didn't say what QAbstractItemModel you used to populate the QComboBox. If you used QSqlQueryModel then just call setQuery() to reset the model.

waynew
19th April 2011, 12:30
I'm populating the combo box from a query and the debug shows the correct number of box entries after an add or a delete.


void DxSpots::loadClusters()
{
qDebug() << "Loading clusters";
ui->cbClusters->clear();
qDebug() << "combo count 1 = " << ui->cbClusters->count();
// Load the stored urls into the combo box
QSqlQuery queryu(::spotsDB);
queryu.exec("Select url from nodes order by url");
int i = 0;
while (queryu.next())
{
qDebug() << "url is " << queryu.value(0).toString();

ui->cbClusters->insertItem(i, queryu.value(0).toString());
i++;
}
qDebug() << "combo count 2 = " << ui->cbClusters->count();


This slot is called each time an add or delete is done from the options form.