[Qt-interest] Simple qSort() question

william.crocker at analog.com william.crocker at analog.com
Thu Jan 13 04:30:05 CET 2011



Joshua Grauman wrote:
> 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.

You don't.
You only have to write your own lessThan.

     void qSort ( begin, end, lessThan )

> 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
>>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
> 



More information about the Qt-interest-old mailing list