Solved Does deleting something from QStringList in middle of for loop will have affect some thing.
-
I have below scenario
one QStringList test;
now below code
for(const QString &str : test)
{
if( str .contains("a))
{
test.remove(str);
}
}My concern i am deleting something from list test in middle of for loop of iterating test list
Will it will invalidate iterators something like this? -
@Ayush-Gupta Please read the link I posted:
"Removes the item associated with the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()).". So, nothing is invalidated. -
@Ayush-Gupta You should use iterators in such a case for your loop and https://doc.qt.io/qt-5/qlist.html#erase to remove elements inside the loop.
-
But it seems iterators will be invalidated.How can I handle that
-
@Ayush-Gupta Please read the link I posted:
"Removes the item associated with the iterator pos from the list, and returns an iterator to the next item in the list (which may be end()).". So, nothing is invalidated.