문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top