How to remove certain portion of elements(QList)
-
I need some function which would allow me do something like that:
items.removeFromTo(157, 2877); //remove all elements between 157 and 2877
I need to use such a function numerous times, so do that manually for every element through loop worst idea.
-
Found one: erase(from, to);
-
@Engelard
Well,QList
does not have a "range delete" method. Items will have to be removed in a loop. I don't know why you need to do numerous range deletions, or whether you've actually timed these. WouldQVector
with its http://doc.qt.io/qt-5/qvector.html#remove-1remove(int i, int count)
have been a better choice? Or some other data structure? -
@Engelard
You are quite right! I spottedremove()
, and noticed thatQList
did not offer acount
overload, but did not occur to me to look forerase()
!I still wonder though:
so do that manually for every element through loop worst idea.
Erasing from a list still requires visiting each element, so I would have thought that
erase()
will simply be of the same order as looping through each element anyway.