Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top