Chances are someone else wrote some function that does that for you. Else you would have to write it yourself. I'm pretty sure qSort() doesn't do that for you.
There's always the possibility of the struct I mentioned before, but only containing the thing you want to sort on and an integer. You copy the list, fill the integers with the original index and sort the new list based on your criteria. You can return just the list of integers if you prefer.
Maybe it still doesn't suit your needs, but I'll give you a jump start on my idea.
-- spoiler --
struct SortItem
{
int origIndex;
bool operator<(const SortItem &other) const
{
return itemToSort < other.itemToSort;
}
};
// ...
QList<SortItem> items;
// fill the list
QList<SortItem> sortedItems = items;
qSort(sortedItems);
// run through sortedItems and get the origIndex to reference the item in the original lists.
struct SortItem
{
QString itemToSort;
int origIndex;
bool operator<(const SortItem &other) const
{
return itemToSort < other.itemToSort;
}
};
// ...
QList<SortItem> items;
// fill the list
QList<SortItem> sortedItems = items;
qSort(sortedItems);
// run through sortedItems and get the origIndex to reference the item in the original lists.
To copy to clipboard, switch view to plain text mode
Bookmarks