Results 1 to 3 of 3

Thread: C++/Qt4: QTableView with QSortFilterProxyModel as model doesn't update values

  1. #1
    Join Date
    Oct 2016
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default C++/Qt4: QTableView with QSortFilterProxyModel as model doesn't update values

    Hi, I have a QTableView with a QSortFilterProxyModel as it's model. Source model for the proxy is a custom model subclassing QAbstractTableModel. I update the source model every minute. I made a function for that thats get called every minute:

    Qt Code:
    1. void CustomModel::update()
    2. {
    3. for(int i = 0; i < alarms.size(); i++)
    4. alarms[i]->addMinute();
    5.  
    6. timer->start((60 - QTime::currentTime().second()) *1000);
    7.  
    8. emit dataChanged(index(0, 0), index(alarms.size(), 3));
    9. }
    To copy to clipboard, switch view to plain text mode 

    The problem is that the proxy model doesn't update it's values, except if i repaint the window (by minimizing and maximizing the window), or click a table header. Also i want it sorted, and does that a couple of times, but later it stops. Here is the code i use on my main window:

    Qt Code:
    1. proxyModel->setSourceModel(&CustomModelInstance);
    2. proxyModel->setDynamicSortFilter(true);
    3. proxyModel->sort(2, Qt::DescendingOrder);
    To copy to clipboard, switch view to plain text mode 

    I thought that by calling dataChanged() when updating values on the source model every proxy model should also update itself. What im doing wrong?
    Last edited by lugarci2; 22nd October 2016 at 18:59. Reason: spelling corrections

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt4: QTableView with QSortFilterProxyModel as model doesn't update values

    I don't see any problem aside from your end index being wrong.
    Row value is one off, maybe the column value as well (does the model have 4 columns?)

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    lugarci2 (1st February 2017)

  4. #3
    Join Date
    Oct 2016
    Posts
    6
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: C++/Qt4: QTableView with QSortFilterProxyModel as model doesn't update values

    the end index values were off by one, the model has 3 columns. Now everything is working fine!, thanks!

Similar Threads

  1. How to auto update values on QTableView?
    By vrltwe in forum Newbie
    Replies: 3
    Last Post: 30th December 2013, 21:19
  2. Replies: 6
    Last Post: 22nd November 2011, 04:53
  3. Replies: 1
    Last Post: 19th November 2009, 00:21
  4. Replies: 12
    Last Post: 5th July 2009, 17:03
  5. Replies: 9
    Last Post: 7th November 2006, 16:10

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.