I have two QList
s for which I need to determine the intersection (in this specific case, two QStringList
s, 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.
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());