Pergunta

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.

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top