|
本帖最后由 realfan 于 2017-9-22 15:57 编辑
sortFileName是类的非静态成员函数,调用时一定要通过一个对象的。所以不能这样调用。
解决方法:
1,将sortFileName成员声明为静态成员函数:
static bool sortFileName(const QString &str1, const QString &str2);
2. qSort(sortList->begin(), sortList->end(), &MainWindow::sortFileName);
3.函数写得也不对,应该是
bool MainWindow::sortFileName(const QString & str1, const QString & str2)
{
return str1.compare(str2, Qt::CaseInsensitive) < 0;
}
还有种方法,就是把sortFileName写成普通函数
bool sortFileName(const QString & str1, const QString & str2)
{
return str1.compare(str2, Qt::CaseInsensitive) < 0;
}
qSort(sortList->begin(), sortList->end(), sortFileName);
这样与可以。
最后提醒一下,建议使用std::sort, qSort将来可能会从Qt中拿掉。
std::sort(sortList->begin(), sortList->end(),
[](const QString & str1, const QString & str2){return str1.compare(str2, Qt::CaseInsensitive) < 0;});
|
|