Pergunta

I have two QLists for which I need to determine the intersection (in this specific case, two QStringLists, but I would assume that this would apply to every container so long as T implements operator==()).

What is the Qt way to determine intersection between lists?

EDIT:

Order and duplication are not a concern. I am just looking for the items that exist in both lists.

Foi útil?

Solução

It depends on exactly what you're trying to accomplish. Factors such as duplicate entires and ordering come into play if you're dealing with lists. If you just want to know which elements the two lists have in common you could do this:

QSet<QString> intersection = list1.toSet().intersect(list2.toSet());
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top