PDA

View Full Version : QSortFilterProxyModel & QTreeView



Bear
27th January 2006, 19:40
I have a Model that I've built that represents a tree of nodes (parented children which are key/value pairs, the default role returning the key), very similar to the simple example provided. When I connect it to a QTreeView, I can expand the tree, collapse it, select it, edit it... basically anything one would expect.

If, however, I instance a QSortFilterProxyModel with my model as the source, and pass that instance to the QTreeView, as soon as I try to expand any node, the application blows up with

warning: ASSERT failure in QVector<T>::at: "index out of range",
file C:/Qt/4.1.0/include/QtCore/../../src/corelib/tools/qvector.h, line 211

I've run it though a debugger, but I'm not proficient enough with the internals of Qt to figure out the magic going on inside of the QSortFilterProxyModel. Right now, it should just be acting as a one-to-one map, because I've done nothing more than set my model as the source, and it as the model for the QTreeView.

What I have seen is that it occurs when the request comes from qitemdelegate.cpp looking for the Qt::SizeHintRole (line 258).

Any suggestions would be very welcome!

Thanks!
Gary

wysota
28th January 2006, 01:42
Could we see the backtrace?

inz
31st January 2006, 14:16
Hi, I've encountered the same error twice. I solved it the first time but not the second :( .

For the first error, I used in some loops invalid indexes as ending conditions, but proxy model does not seems to appreciate access to invalid indexes (out of range) whereas in my custom model, out-of-range index requests return invalid indexes. So I rewrite my loops to avoid out-of-range index request.

For the second error, I've not found any solution yet. It seems that proxy model maintains persistent indexes. Thoses indexes are modified by the QTreeView when expanding. But when the QSortFilterProxyModel tries to access thoses indexes, they seems to be invalid. I don't understand why thoses indexes are invalid, since they are set by the QTreeView.

Edit:
I've found a workaround for my case. I disconnect the signal between modelReset() and reset() in my derived class constructor of QSortFilterProxyModel and it seems to work. But I only have to fully expand/collapse the tree, maybe there's more to do in your case.

Bear
31st January 2006, 16:04
Hi, I've encountered the same error twice. I solved it the first time but not the second :( .


On a whim, I downloaded the 4.1.1 alpha, and sure enough everything works fine. A quick diff between that and 4.1.0 indicated that checks were added to test if the index exists before trying to use it. It appears that this is a known bug, although I couldn't find it in the task tracker.