Results 1 to 2 of 2

Thread: QSortFilterProxyModel not updating View

  1. #1
    Join Date
    Jul 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default QSortFilterProxyModel not updating View

    As the title says I have QTableViews with QFilteProxyModels.But when any change is made to the database,the view is not updated.
    Here is my code
    Qt Code:
    1. void Factory::setupDealersTabModel()
    2. {
    3. QSqlQueryModel *model = new QSqlQueryModel(this);
    4. QSqlQuery q(*db);
    5. QString query = "select name,organization,debt from dealers";
    6.  
    7. if(!q.exec(query)){
    8. QSqlError err = q.lastError();
    9. QMessageBox::critical(this,"Error",err.text());
    10. }
    11. model->setQuery(query);
    12.  
    13. //test code
    14. dealer_proxy_model = new QSortFilterProxyModel(this);
    15. dealer_proxy_model->setDynamicSortFilter(true);
    16.  
    17. //set model
    18. ui->dealers_tableview->setModel(dealer_proxy_model);
    19. dealer_proxy_model->setSourceModel(model);
    20. }
    21.  
    22. void Factory::setupSuppliersTabModel()
    23. {
    24. QSqlQueryModel *model = new QSqlQueryModel(this);
    25. QSqlQuery q(*db);
    26. QString query = "select name,organization,balance from supplier";
    27.  
    28. if(!q.exec(query)){
    29. QSqlError err = q.lastError();
    30. QMessageBox::critical(this,"Error",err.text());
    31. }
    32. model->setQuery(query);
    33.  
    34. //set proxy
    35. supplier_proxy_model = new QSortFilterProxyModel(this);
    36. supplier_proxy_model->setDynamicSortFilter(true);
    37.  
    38. //set model
    39. supplier_proxy_model->setSourceModel(model);
    40. ui->suppliers_tableview->setModel(supplier_proxy_model);
    41. }
    To copy to clipboard, switch view to plain text mode 

    ---

  2. #2
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: QSortFilterProxyModel not updating View

    Hi, you don't show how you're updating your database. The model must inform the view that the data has changed. You don't seem to be subclassing QSqlQueryModel and from the docs, I see the following:
    The model is read-only by default. To make it read-write, you must subclass it and reimplement setData() and flags(). Another option is to use QSqlTableModel, which provides a read-write model based on a single database table.
    So, can you elaborate on how your model is changed?
    Last edited by jefftee; 28th July 2016 at 00:56.
    I write the best type of code possible, code that I want to write, not code that someone tells me to write!

Similar Threads

  1. Rapid updating of QSortFilterProxyModel
    By jkrienert in forum Newbie
    Replies: 15
    Last Post: 4th January 2015, 17:57
  2. Replies: 0
    Last Post: 26th June 2014, 14:03
  3. QSortFilterProxyModel search and view scroll help
    By waynew in forum Qt Programming
    Replies: 1
    Last Post: 10th November 2011, 01:58
  4. Replies: 0
    Last Post: 2nd February 2011, 12:02
  5. QSortFilterProxyModel not updating
    By karn862 in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2010, 23:16

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
  •  
Qt is a trademark of The Qt Company.