Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QList - Best way to insert in the middle?
QtWS25 Last Chance

QList - Best way to insert in the middle?

Scheduled Pinned Locked Moved Solved General and Desktop
qlist
4 Posts 2 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maximus
    wrote on last edited by A Former User
    #1

    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);
    }


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • T Offline
      T Offline
      t3685
      wrote on last edited by
      #2

      Check the documentation of QList

      http://doc.qt.io/qt-5/qlist.html#insert

      M 1 Reply Last reply
      0
      • T t3685

        Check the documentation of QList

        http://doc.qt.io/qt-5/qlist.html#insert

        M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        @t3685

        oh insert does this already. I mixed it with replace()
        Thanks! have to learn to read docs..


        Free Indoor Cycling Software - https://maximumtrainer.com

        T 1 Reply Last reply
        0
        • M maximus

          @t3685

          oh insert does this already. I mixed it with replace()
          Thanks! have to learn to read docs..

          T Offline
          T Offline
          t3685
          wrote on last edited by
          #4

          @maximus

          Sometimes the answer is right in front of you :)

          1 Reply Last reply
          1

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved