写法一
QList<test> s;
test aa;
test bb;
test cc;
aa.num = "14";
bb.num = "2";
cc.num = "3";
s.append(aa);
s.append(bb);
s.append(cc);
qSort(s.begin(), s.end(),[](const test &infoA,const test &infoB){return infoA.num.toDouble() < infoB.num.toDouble();});
for(int i = 0; i < s.count() ; i++)
{
qDebug() << s.at(i).num;
}
写法二
#include "widget.h"
#include <QApplication>
#include <QtDebug>
//排列判断
int compare(const test &infoA,const test &infoB)
{
return infoA.num.toDouble() < infoB.num.toDouble();
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QList<test> s;
test aa;
test bb;
test cc;
aa.num = "14";
bb.num = "2";
cc.num = "3";
s.append(aa);
s.append(bb);
s.append(cc);
qSort(s.begin(), s.end(),compare);
for(int i = 0; i < s.count() ; i++)
{
qDebug() << s.at(i).num;
}
return a.exec();
}