How to sort QList<QVariant> in Qt?

dexterous picture dexterous · Feb 5, 2014 · Viewed 51.6k times · Source

I have the following datastructure.

QList<QVariant> fieldsList

How can I sort this list? This list contains strings. I want to sort the fieldList alphabetically?

Answer

albertTaberner picture albertTaberner · Dec 1, 2014

In Qt5, it seems qSort is deprecated. It's recommended to use:

#include <algorithm>
QList<QVariant> fieldsList;
std::sort(fieldsList.begin(), fieldsList.end());

Reference: site