Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Qt way to obtain the intersection between two QLists?

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.

like image 385
Freedom_Ben Avatar asked Jul 09 '13 22:07

Freedom_Ben


1 Answers

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());
like image 120
Chris Avatar answered Nov 08 '22 21:11

Chris