
Originally Posted by
jean
to JPN : the Trolltech doc for qSort() only treat single variable QList. Operators are presented for performing special sortings.
In your case QList deals with myData struct. QList doesn't care at all what the composition of that type. To be able to use qSort(), you need to implement either
1) myData::operator<():
struct myData {
bool operator<(const myData& other) const {
return namefile < other.namefile; // sort by namefile
}
...
};
// usage:
QList<myData> list;
...
qSort(list);
struct myData {
bool operator<(const myData& other) const {
return namefile < other.namefile; // sort by namefile
}
...
};
// usage:
QList<myData> list;
...
qSort(list);
To copy to clipboard, switch view to plain text mode
OR
2) a LessThan function which does the sorting instead of using operator<():
bool namefileLessThan(const myData &d1, const myData &d2)
{
return d1.namefile < d2.namefile; // sort by namefile
}
// usage:
QList<myData> list;
...
qSort(list.begin(), list.end(), namefileLessThan);
bool namefileLessThan(const myData &d1, const myData &d2)
{
return d1.namefile < d2.namefile; // sort by namefile
}
// usage:
QList<myData> list;
...
qSort(list.begin(), list.end(), namefileLessThan);
To copy to clipboard, switch view to plain text mode
Bookmarks