Remove strings contained in one QStringList, from another QStringList

4.7k Views Asked by At

I was wondering if anyone knew of a Qt library method that can take two QStringList and remove all of the strings contained in one list from the second list.

2

There are 2 best solutions below

0
On BEST ANSWER

You could use the QList::toSet() method and do some my_set1.substract(my_set2), and then go back QSet::toList(). But this is just to play around with conversion code. You'd better code the logic yourself with the given lists, it will be faster and won't involve useless memory allocation (even if temporary)

0
On

There is no library function in QList nor QStringList.

But you can write your own method:

void remove(QStringList& list, const QStringList& toDelete){
  QStringListIterator i(toDelete);
  while(i.hasNext()){
    list.removeAll(i.next());
  }
}