PDA

View Full Version : C++/Qt4: QTableView with QSortFilterProxyModel as model doesn't update values



lugarci2
22nd October 2016, 17:57
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:



void CustomModel::update()
{
for(int i = 0; i < alarms.size(); i++)
alarms[i]->addMinute();

timer->start((60 - QTime::currentTime().second()) *1000);

emit dataChanged(index(0, 0), index(alarms.size(), 3));
}


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:



proxyModel->setSourceModel(&CustomModelInstance);
proxyModel->setDynamicSortFilter(true);
proxyModel->sort(2, Qt::DescendingOrder);


I thought that by calling dataChanged() when updating values on the source model every proxy model should also update itself. What im doing wrong?

anda_skoa
23rd October 2016, 10:18
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,
_

lugarci2
24th October 2016, 16:47
the end index values were off by one, the model has 3 columns. Now everything is working fine!, thanks!