[Qt-interest] Simple qSort() question
Joshua Grauman
jnfo-c at grauman.com
Thu Jan 13 02:36:37 CET 2011
No'am,
Thanks for the reply. I know I could use the method you outlined, but then
I'd need to create my own sort. Not a big deal, but since qSort is already
optimized/etc, I was just seeing if there were some Qt specific tricks,
functions, classes, etc. that would make this easy for me that I didn't
know of.
Thanks again.
Josh
>
>
>> -----Original Message-----
>> From: qt-interest-bounces+noam.rosenthal=nokia.com at qt.nokia.com
>> [mailto:qt-interest-bounces+noam.rosenthal=nokia.com at qt.nokia.com] On
>> Behalf Of ext Joshua Grauman
>> Sent: Wednesday, January 12, 2011 4:03 PM
>> To: qt-interest at qt.nokia.com
>> Subject: [Qt-interest] Simple qSort() question
>>
>> Hello all,
>>
>> I have three QStringLists that I would like to sort. They all are
>> guarenteed to have the same number of items in them with rows that
>> correspond to each other. I often want to sort my data based on one of
>> the
>> lists. It's easy enough to sort a single list, but then the data in the
>> other two lists doesn't match. Is there an easy way to do this that I'm
>> not thinking of?
>
> Have a fourth list of indices only (e.g. QList<int>) or a structure that contains both the int and the string, and sort it using the first list's data.
> Then when you need any ordered data, you go through this indexed list, and fetch the values from the original 3 lists, e.g.
>
> For (int i = 0; i < indices.size(); ++i) {
> int index = indices[i];
> QString s1 = list1[index];
> QString s2 = list2[index];
> QString s3 = list3[index];
> }
>
> Btw this is not a Qt question, it's more of a general data-model question :)
>
> No'am
>
More information about the Qt-interest-old
mailing list