PDA

View Full Version : QSortFilterProxyModel with changing data



kemp
8th September 2010, 10:02
HI!

I have a list of descriptors. These descriptors are constantly changing data. I build the tree items in the model from these descriptors.


m_pMyTreeModel = new CMyTreeModel();
//
m_pMyTreeModel->initializeModel(m_listDescriptors);
//
m_pFilterModel = new CMySortFilterProxyModel(this);
//
m_pFilterModel->setSourceModel(m_pMyTreeModel);
//
m_pTree->setModel(m_pFilterModel);

Each descriptor is connected to the item that is created in the model. I am emitting the signals
layoutAboutToBeChanged() and
layoutChanged() in a timer so that the data is updated correctly in the view.

The problem is that the code gets very slow with few thousand items (3000+).
I tried to implement the functions for better performance:



bool hasChildren(const QModelIndex &parent) const;
bool canFetchMore(const QModelIndex &parent) const;
void fetchMore(const QModelIndex &parent);


but get stuck with the
void fetchMore(const QModelIndex &parent); function. In this function i should create the tree items, but the problem is that i have no descriptors here to connect them to the tree items.
I don't know if this is the best approach to update the data in the model. I think that there is a better way to do this, but have no idea how.

Please help.

kemp
9th September 2010, 09:02
Can someone help me please?

kemp
10th September 2010, 20:31
OK, I changed the tree item and made it more lightweight, not it is no more derived from QObject. I am now using a QMap with the descriptors and items. The performance is good now, but I am facing another problem that I had also before. There are to mani handles open - with 5000 items, there are arounf 15000 handles and the memory is raising beyond 250 MB.

ChrisW67
11th September 2010, 07:30
What is a "handle" and why do you think they consume about 16 kilobytes a piece? Are you perhaps allocating but never freeing objects in memory as the model gets used?

kemp
13th September 2010, 07:27
The problem was in an library that I was using and not Qt related. Thanks for the help.