[Qt-interest] QSortFilterProxyModel bug
Pascal Patry
iscy at invalidip.com
Thu Mar 5 19:29:22 CET 2009
Qt 4.5.0 introduced a bug inside QSortFilterProxyModel.
1. Create a QTreeView
2. Associate a model (class that inherit from QStandardItemModel)
3. Associate a proxy (QSortFilterProxyModel)
4. Set the sorting enabled on column 0
5. Insert a few items
=> At this point, everything is sorted correctly. All good.
6. Reimplement 'canFetchMore()' and 'fetchMore()' on the concrete model
canFetchMore() { return true; }
fetchMore() { // Create the children here }
7. Hit the "+" on the view where 'fetchMore' will create some items
=> At this point, the sort is totally broken.
The QTreeView has only one column. When we create the items, we use the
function "QStandardItem::appendRows()". This function will
cause "QSortFilterProxyModelPrivate::_q_sourceColumnsInserted(...)" to be called. Once
this happens, we hit the bug on the line at "qsortfilterproxymodel.cpp:1189".
The line is:
"source_sort_column += end - start + 1;"
Obviously, 'end' and 'start' are both 0 because we have only one column. So this will
set "source_sort_column" to be 1. Since 1 is not a valid column, the sorting predicate
(QSortFilterProxyModelLessThan) will use "sort_column" as being this value, hence
retrieving 2 invalid QModelIndex. That will lead to a totally broken sort coming from the
model.
Is this problem already known? If so, is there a patch somewhere to fix this?
Thank you,
More information about the Qt-interest-old
mailing list