Thanks for the response
When data arrives from source 2 it is not adding a new row, but rather adding information to or updating information on an existing row. Therefore insertRows will not work.
I reset the whole model each time I get new information from source 2 because it is expensive for me to establish which row of the model would change as a result of the new data. When I say expensive, I mean that I would need to do a search (linear time) through a vector to establish the row and I don't want to have to do this every time. Of course, I don't want to have to begin/endResetModel each time new data from source 2 arrives either as this causes a lot of work for the QTableView.
So this is what I'm trying:
- beginResetModel
- update model data
- [beginResetModel, update model data] X 100
- endResetModel
i.e. beginResetModel could be emitted 100 times without endResetModel being emitted. And then endResetModel would be emitted once.
This is the relevant code that creates the endResetModel timer and handles data from source 2:
MyModel::MyModel()
{
...
source2Timer = new QTimer(this);
source2Timer->setInterval(500);
source2Timer->setSingleShot(true);
connect(source2Timer, SIGNAL(timeout()), this, SLOT(endResetModel()));
}
void MyModel::HandleSource2Data(const DataItem& item)
{
beginResetModel();
source2Cache.Add(item);
source2Timer->start();
}
MyModel::MyModel()
{
...
source2Timer = new QTimer(this);
source2Timer->setInterval(500);
source2Timer->setSingleShot(true);
connect(source2Timer, SIGNAL(timeout()), this, SLOT(endResetModel()));
}
void MyModel::HandleSource2Data(const DataItem& item)
{
beginResetModel();
source2Cache.Add(item);
source2Timer->start();
}
To copy to clipboard, switch view to plain text mode
Or do I NEED to emit an endResetModel for every beginResetModel signal emitted? Or is what I'm planning OK?
Bookmarks