Vlado Klimovský Vlado Klimovský - 6 months ago 69
C++ Question

Removing duplicates from a QList

For years I have been using the following pattern to remove duplicates from an object of the C++


std::vector<int> cont;
std::sort(cont.begin(), cont.end());
cont.erase(std::unique(cont.begin(), cont.end()), cont.end());

Now I am wondering if the same paradigm is the one to be used with the Qt
class, or if there is a more elegant way to do it.


I don't know about performance, but what about converting the QList into a QSet ?

QList<int> myQList;
QSet<int> = QSet::fromList(myQList);
// or
QSet<int> = myQList.toSet();

(and maybe convert it back to a QList if needed with QList::fromSet())