QList - Best way to insert in the middle?
-
wrote on 25 Apr 2015, 17:23 last edited by A Former User
I have a custom QList of custom object : QList<Interval>
I would like to insert an object in the middle, and pushing the elements at the location of the insert to the right. so that the list size increase by 1.
Wondering if there is a function for that in QList, or do I have to do it manually? (create a new QList and copy the right side one by one)PseudoCode to insert :
int positionToInsert = 5;
Interval intervalToInsert;
newLstInterval = oldLstInterval;newLstInterval.insert(5, intervalToInsert);
for (int i=insertPosition; i<oldListInterval.size(); i++) {
newLstInterval.insert(i+1, oldLstInterval.at(i);
} -
wrote on 25 Apr 2015, 18:14 last edited by
Check the documentation of QList
-
Check the documentation of QList
-
oh insert does this already. I mixed it with replace()
Thanks! have to learn to read docs..
4/4