[Qt-interest] Simple qSort() question
noam.rosenthal at nokia.com
noam.rosenthal at nokia.com
Thu Jan 13 02:01:57 CET 2011
>-----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