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. Will the items pointer changed after QList::RemoveAt(i)?
QtWS25 Last Chance

Will the items pointer changed after QList::RemoveAt(i)?

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 5 Posters 1.7k 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.
  • O Offline
    O Offline
    opengpu2
    wrote on last edited by A Former User
    #1

    How QList store data in memory? Like list or array?
    Thank you!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      "Internally, QList<T> is represented as an array of T "

      so array.

      jsulmJ 1 Reply Last reply
      0
      • mrjjM mrjj

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

        "Internally, QList<T> is represented as an array of T "

        so array.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @mrjj That's only part of the truth :-)
        "Internally, QList<T> is represented as an array of T if sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. Otherwise, QList<T> is represented as an array of T* and the items are allocated on the heap."

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        O mrjjM 3 Replies Last reply
        1
        • jsulmJ jsulm

          @mrjj That's only part of the truth :-)
          "Internally, QList<T> is represented as an array of T if sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. Otherwise, QList<T> is represented as an array of T* and the items are allocated on the heap."

          O Offline
          O Offline
          opengpu2
          wrote on last edited by
          #4

          @jsulm so if sizeof(T) > sizeof(void*), remove an item does not influence the other item's pointer address in memory...

          1 Reply Last reply
          0
          • jsulmJ jsulm

            @mrjj That's only part of the truth :-)
            "Internally, QList<T> is represented as an array of T if sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. Otherwise, QList<T> is represented as an array of T* and the items are allocated on the heap."

            O Offline
            O Offline
            opengpu2
            wrote on last edited by
            #5

            @jsulm thank you very much

            1 Reply Last reply
            0
            • jsulmJ jsulm

              @mrjj That's only part of the truth :-)
              "Internally, QList<T> is represented as an array of T if sizeof(T) <= sizeof(void*) and T has been declared to be either a Q_MOVABLE_TYPE or a Q_PRIMITIVE_TYPE using Q_DECLARE_TYPEINFO. Otherwise, QList<T> is represented as an array of T* and the items are allocated on the heap."

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @jsulm
              Thank you.
              Last part also important :)
              So if not Q_MOVABLE_TYPE etc, its a list.

              So the short answer is , depends on T , i guess.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                I'd recommend reading this excellent blog about Qt's containers.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                kshegunovK 1 Reply Last reply
                2
                • SGaistS SGaist

                  Hi,

                  I'd recommend reading this excellent blog about Qt's containers.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #8

                  @SGaist

                  Looks interesting. I'll read it when I have the time, although I already know Qt's containers have a somewhat poorer performance on average. However I just couldn't bring myself to like the C-style underscore API of STL. And I couldn't help myself but think that the whole "move semantics" nonsense in C++11 was invented only to mitigate the STL's containers' deep copy inefficiencies. Still, the points raised in the article are valid.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  0

                  • Login

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