[Qt-interest] [QModelIndex/QAbstractItemView] sorted/not sorted ?

BRM bm_witness at yahoo.com
Thu Dec 3 15:19:07 CET 2009


----- Original Message ----

> From: "St.Vogelsang at gmx.de" <St.Vogelsang at gmx.de>
> According to the documentation:
> http://qt.nokia.com/doc/4.5/qabstractitemview.html#selectedIndexes
> QModelIndexList QAbstractItemView::selectedIndexes () const;
> provides a _not_ sorted list. 
> Since I really need a sorted one, I implemented a sort algorithm. 
> But my debug-code shows always a already sorted List. So I'm interested in understanding when (maybe memory allocation) or on which other circumstances the list gets unsorted. 
> Or is it a documentation bug?

>From my (limited) experience with that part of the API - you can select items in a row or randomly.
Qt provides a list of all the selected items, typically from start to end as they are displayed without any sorting applied.
The list may also not be fully continuous - that is you might have indices 1, 3-5, and 7 selected.

So - to sum it - it'll be sorted by index, but not necessarily continuous; not by the data be displayed.
That's not to say you can't sort it; though when I did my work a while back with it it was kind of bumpy as there doesn't seem to be an easy way to move around entries.
(I resorted to remove from one index then adding it back at another index; and had to be very careful about the order I did things in in order to keep the original selection list valid.)

Ben




More information about the Qt-interest-old mailing list