Frage

Is there a methode or simple approach to do this?

Given a list with:

D A B A B C D D

I want the list to be reduced to:

A B C D

Otherwise I will just write something to process in the background.

War es hilfreich?

Lösung

It depends on how is your data storen and passed to the view. Generally, the simpliest way to remove duplicates from a list of element is converting it to set:

QStringList values;
//...
QSet<QString> set = values.toSet();

After that you can convert the set back to list using toList or iterate over a set using usual foreach loop. Note that QSet is unordered. If you want to sort your strings, convert the set to list and sort the list using qSort.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top