Results 1 to 3 of 3

Thread: QComboBox refresh problem

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QComboBox refresh problem

    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.

  2. #2
    Join Date
    Apr 2011
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QComboBox refresh problem

    You didn't say what QAbstractItemModel you used to populate the QComboBox. If you used QSqlQueryModel then just call setQuery() to reset the model.

  3. #3
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QComboBox refresh problem

    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.
    Qt Code:
    1. void DxSpots::loadClusters()
    2. {
    3. qDebug() << "Loading clusters";
    4. ui->cbClusters->clear();
    5. qDebug() << "combo count 1 = " << ui->cbClusters->count();
    6. // Load the stored urls into the combo box
    7. QSqlQuery queryu(::spotsDB);
    8. queryu.exec("Select url from nodes order by url");
    9. int i = 0;
    10. while (queryu.next())
    11. {
    12. qDebug() << "url is " << queryu.value(0).toString();
    13.  
    14. ui->cbClusters->insertItem(i, queryu.value(0).toString());
    15. i++;
    16. }
    17. qDebug() << "combo count 2 = " << ui->cbClusters->count();
    To copy to clipboard, switch view to plain text mode 
    This slot is called each time an add or delete is done from the options form.

Similar Threads

  1. Replies: 2
    Last Post: 14th January 2011, 16:09
  2. QFile::remove() strange refresh problem in windows desktop
    By ramazangirgin in forum Qt Programming
    Replies: 6
    Last Post: 8th December 2010, 03:42
  3. Replies: 7
    Last Post: 6th November 2010, 09:32
  4. QWidget Refresh Problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 15th January 2008, 12:24
  5. QTableView refresh problem
    By tebessum in forum Qt Programming
    Replies: 3
    Last Post: 29th December 2006, 12:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.