PDA

View Full Version : Sort Qlist and return index



enricong
18th July 2012, 20:20
I have a qlist of floats that I would like to sort. However I am looking for a list of the sorted indices.
I could have a qhash of index and float pairs, but I don't know how to sort a qhash on the value.

wysota
18th July 2012, 20:39
So you don't want to sort the original list but rather have a new list that containes a list of indexes of the original list that would make it a sorted list, yes?

I think the easiest way is to use a functor that takes the original list as a parameter as a custom LessThan operator for qSort() that would operate on a list containing indexes of the original list (so starting with a sorted list of 0..(originalList.count()-1)).

enricong
20th July 2012, 14:06
I was hoping there was an easier way than that like how you can sort columns on a table.
Are there any examples of howto create a custom LessThan to pass to qSort?

wysota
20th July 2012, 14:19
I was hoping there was an easier way than that
It is quite easy.


like how you can sort columns on a table.
And how do you do that?


Are there any examples of howto create a custom LessThan to pass to qSort?
I'm sure there are some in the docs. And here is one that uses a functor:
http://qt-project.org/forums/viewthread/4978 (which of course does something completely different from what you want).