[Interest] QList and erase problem...

Julien Cugnière julien.cugniere at gmail.com
Mon Sep 14 17:45:23 CEST 2015

2015-09-14 17:13 GMT+02:00 Igor Mironchik <igor.mironchik at gmail.com>:
> Hi,
> it seems that problem not in the iterating and deletion from cantainer...

Yes it is. As Andre told you, erasing from the list invalidates
iterators, including the one returned by end(). As you cache the "end"
iterator in the "last" variable at the start of the loop, after the
first erase you are working with an invalid iterator, and probably
iterate past the end of your list. As a rule, never save the "end"
iterator in a variable if you're going to modify your container.

The fix is to use "while (it != images.end()) {".

More information about the Interest mailing list