[Interest] qSort replacement
Rainer Wiesenfarth
rainer_wiesenfarth at trimble.com
Wed Jul 21 18:22:44 CEST 2021
On Wed, Jul 21, 2021 at 6:07 PM Joshua Grauman <jnfo-d at grauman.com> wrote:
> [...] I can't figure out how to
> use std::sort to sort a QList with a custom compare function. [...]
> bool variantLessThan(const QVariant &v1, const QVariant &v2)
> {
> return v1.toString() < v2.toString();
> }
>
> qSort(fieldsList.begin(), fieldsList.end(), variantLessThan);
[...]
>
If you are using C++17 you may also use lambdas:
std::sort(fieldsList.begin(), fieldsList.end(), [](const QVariant &v1,
const QVariant &v2) {
return v1.toString() < v2.toString();
});
(untested)
Cheers, Rainer
--
Software Engineer | Trimble Imaging Division
Rotebühlstraße 81 | 70178 Stuttgart | Germany
Office +49 711 22881 0 | Fax +49 711 22881 11
http://www.trimble.com/imaging/ | http://www.inpho.de/
Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim
Eingetragen beim Amtsgericht Darmstadt unter HRB 83893,
Geschäftsführer: Rob Reeder, Jürgen Kesper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210721/c6947df5/attachment.html>
More information about the Interest
mailing list