What is the Qt way to get the intersection between two QList?

I have two QList for which I need to define an intersection (in this particular case, two QStringList s, but I would suggest that this applies to each container as long as T implements operator==() ).

What is the Qt way to determine the intersection of lists?

EDIT:

Order and duplication are not a problem. I'm just looking for elements that exist on both lists.

+6
source share
1 answer

It depends on what you are trying to accomplish. Factors such as duplication and order come into play if you are dealing with lists. If you just want to know which items have two lists, you can do this:

 QSet<QString> intersection = list1.toSet().intersect(list2.toSet()); 
+12
source

Source: https://habr.com/ru/post/949058/


All Articles