[Interest] qSort replacement
Joshua Grauman
jnfo-d at grauman.com
Wed Jul 21 18:05:24 CEST 2021
Hi all,
I see that qSort is deprecated in newer versions of Qt. I can also see
that std::sort is intended to replace it. But I can't figure out how to
use std::sort to sort a QList with a custom compare function. With qSort
you could supply your own comparison function to sort however you wanted.
I don't see how to do this with std::sort. Do you have to subclass and
provide a operator< overload? I'd rather just define a comparison
function, is this possible?
Thanks,
Josh
bool variantLessThan(const QVariant &v1, const QVariant &v2)
{
return v1.toString() < v2.toString();
}
qSort(fieldsList.begin(), fieldsList.end(), variantLessThan);
More information about the Interest
mailing list