How to find duplicates in QStringList
General and Desktop
5
Posts
5
Posters
11.2k
Views
1
Watching
-
One way to do that, would be to use a QSet<QString>. Just add all the items from the QStringList to the set like this:
@
QSet<QString> stringSet = QSet<QString>::fromList(myStringList);
if (stringSet.count() < myStringList.count()) {
//throw your error
}
@There are more efficient ways to do it, I guess. If your QStringList is sorted, then it becomes much easier, but you will have to loop over the list in one way or another. The code above loops over your list as well, but the loop is in the ::fromList call instead of in your own code.