class MyClass {
public:
int a;
bool operator<(const MyClass other) const {
return a<other.a;
}
....
};
....
QList<MyClass*> list;
最佳答案
在 C++11 中,您还可以像这样使用 lambda:
QList<const Item*> l;
qSort(l.begin(), l.end(),
[](const Item* a, const Item* b) -> bool { return a->Name() < b->Name(); });
关于c++ - 如何使用 Qt 库(可能是 qSort())对 QList<MyClass*> 进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5103682/