QList - Best way to insert in the middle?
-
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);
} -
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..