Pointer to an element in QListQt: Storing a custom object in a collection by valueSplitting QList into chunks, pointers or references?Can two threads read from the same QList at the same time?How to make QList<Type*> work with indexOf() and custom operator==()?QVariant to QList with unkown list template parameterC++ - pointers in a QListNested QHash Not SavingQtConcurrent::map and list of pointersHow would a QList containing pointers behave when passed by valueQHash removal of specified position till the end of QHash and update the QList accordingly

Is it inappropriate for a student to attend their mentor's dissertation defense?

Could the museum Saturn V's be refitted for one more flight?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

What does “the session was packed” mean in this context?

Watching something be piped to a file live with tail

Can compressed videos be decoded back to their uncompresed original format?

Personal Teleportation: From Rags to Riches

Do UK voters know if their MP will be the Speaker of the House?

What killed these X2 caps?

Forgetting the musical notes while performing in concert

Why can't we play rap on piano?

How do I deal with an unproductive colleague in a small company?

How would I stat a creature to be immune to everything but the Magic Missile spell? (just for fun)

What exploit Are these user agents trying to use?

Is it acceptable for a professor to tell male students to not think that they are smarter than female students?

Is "remove commented out code" correct English?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

Why is it a bad idea to hire a hitman to eliminate most corrupt politicians?

What does the expression "A Mann!" means

Ambiguity in the definition of entropy

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

Why is consensus so controversial in Britain?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

Mathematica command that allows it to read my intentions



Pointer to an element in QList


Qt: Storing a custom object in a collection by valueSplitting QList into chunks, pointers or references?Can two threads read from the same QList at the same time?How to make QList<Type*> work with indexOf() and custom operator==()?QVariant to QList with unkown list template parameterC++ - pointers in a QListNested QHash Not SavingQtConcurrent::map and list of pointersHow would a QList containing pointers behave when passed by valueQHash removal of specified position till the end of QHash and update the QList accordingly













1















I have a list of lists container with this type:



QList< QList<UAVObject *> > objects;


For some reason I would like to access one of the internal lists quickly. Can I store a pointer to an internal list? For example:



QList<UAVObject *>& ref = objects[0];
QList<UAVObject *>* pt = &ref;


Will the value of pt still be valid across different function calls and original objects manipulations? Let's assume that the objects list will only be added to and never removed from.










share|improve this question


























    1















    I have a list of lists container with this type:



    QList< QList<UAVObject *> > objects;


    For some reason I would like to access one of the internal lists quickly. Can I store a pointer to an internal list? For example:



    QList<UAVObject *>& ref = objects[0];
    QList<UAVObject *>* pt = &ref;


    Will the value of pt still be valid across different function calls and original objects manipulations? Let's assume that the objects list will only be added to and never removed from.










    share|improve this question
























      1












      1








      1








      I have a list of lists container with this type:



      QList< QList<UAVObject *> > objects;


      For some reason I would like to access one of the internal lists quickly. Can I store a pointer to an internal list? For example:



      QList<UAVObject *>& ref = objects[0];
      QList<UAVObject *>* pt = &ref;


      Will the value of pt still be valid across different function calls and original objects manipulations? Let's assume that the objects list will only be added to and never removed from.










      share|improve this question














      I have a list of lists container with this type:



      QList< QList<UAVObject *> > objects;


      For some reason I would like to access one of the internal lists quickly. Can I store a pointer to an internal list? For example:



      QList<UAVObject *>& ref = objects[0];
      QList<UAVObject *>* pt = &ref;


      Will the value of pt still be valid across different function calls and original objects manipulations? Let's assume that the objects list will only be added to and never removed from.







      qt qt5






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 8 at 22:38









      ilya1725ilya1725

      1,85432441




      1,85432441






















          1 Answer
          1






          active

          oldest

          votes


















          2














          QList is not based on a STL container and has nothing to do with std::list.
          The invalidation rules specified for the STL containers are not applicable.



          According to the Qt documentation (and my understanding), it uses an array of pointers to the items, unless the item is not larger than a void* and declared as movable (with Q_MOVABLE_TYPE).



          In that case, the item is directly stored in the array and the reference will become invalid when your list will grow (the array of pointers will be reallocated).






          share|improve this answer























          • Ah, that's why they can implement [] access in O(1).

            – ilya1725
            Mar 9 at 1:31











          • @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

            – MasterAler
            Mar 9 at 18:23











          • @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

            – ilya1725
            Mar 11 at 15:11











          • @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

            – MasterAler
            Mar 13 at 11:09











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071969%2fpointer-to-an-element-in-qlist%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          QList is not based on a STL container and has nothing to do with std::list.
          The invalidation rules specified for the STL containers are not applicable.



          According to the Qt documentation (and my understanding), it uses an array of pointers to the items, unless the item is not larger than a void* and declared as movable (with Q_MOVABLE_TYPE).



          In that case, the item is directly stored in the array and the reference will become invalid when your list will grow (the array of pointers will be reallocated).






          share|improve this answer























          • Ah, that's why they can implement [] access in O(1).

            – ilya1725
            Mar 9 at 1:31











          • @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

            – MasterAler
            Mar 9 at 18:23











          • @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

            – ilya1725
            Mar 11 at 15:11











          • @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

            – MasterAler
            Mar 13 at 11:09















          2














          QList is not based on a STL container and has nothing to do with std::list.
          The invalidation rules specified for the STL containers are not applicable.



          According to the Qt documentation (and my understanding), it uses an array of pointers to the items, unless the item is not larger than a void* and declared as movable (with Q_MOVABLE_TYPE).



          In that case, the item is directly stored in the array and the reference will become invalid when your list will grow (the array of pointers will be reallocated).






          share|improve this answer























          • Ah, that's why they can implement [] access in O(1).

            – ilya1725
            Mar 9 at 1:31











          • @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

            – MasterAler
            Mar 9 at 18:23











          • @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

            – ilya1725
            Mar 11 at 15:11











          • @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

            – MasterAler
            Mar 13 at 11:09













          2












          2








          2







          QList is not based on a STL container and has nothing to do with std::list.
          The invalidation rules specified for the STL containers are not applicable.



          According to the Qt documentation (and my understanding), it uses an array of pointers to the items, unless the item is not larger than a void* and declared as movable (with Q_MOVABLE_TYPE).



          In that case, the item is directly stored in the array and the reference will become invalid when your list will grow (the array of pointers will be reallocated).






          share|improve this answer













          QList is not based on a STL container and has nothing to do with std::list.
          The invalidation rules specified for the STL containers are not applicable.



          According to the Qt documentation (and my understanding), it uses an array of pointers to the items, unless the item is not larger than a void* and declared as movable (with Q_MOVABLE_TYPE).



          In that case, the item is directly stored in the array and the reference will become invalid when your list will grow (the array of pointers will be reallocated).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 23:57









          Romha KorevRomha Korev

          2,2671423




          2,2671423












          • Ah, that's why they can implement [] access in O(1).

            – ilya1725
            Mar 9 at 1:31











          • @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

            – MasterAler
            Mar 9 at 18:23











          • @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

            – ilya1725
            Mar 11 at 15:11











          • @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

            – MasterAler
            Mar 13 at 11:09

















          • Ah, that's why they can implement [] access in O(1).

            – ilya1725
            Mar 9 at 1:31











          • @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

            – MasterAler
            Mar 9 at 18:23











          • @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

            – ilya1725
            Mar 11 at 15:11











          • @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

            – MasterAler
            Mar 13 at 11:09
















          Ah, that's why they can implement [] access in O(1).

          – ilya1725
          Mar 9 at 1:31





          Ah, that's why they can implement [] access in O(1).

          – ilya1725
          Mar 9 at 1:31













          @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

          – MasterAler
          Mar 9 at 18:23





          @ilya1725, compared to stl containers, QList is more of a std::deque, that's why there also exists QLinkedList, which is more of a list

          – MasterAler
          Mar 9 at 18:23













          @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

          – ilya1725
          Mar 11 at 15:11





          @MasterAler, I did not know that, thank you. Why not call the containers the way they are, i.e. dequeue and list?

          – ilya1725
          Mar 11 at 15:11













          @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

          – MasterAler
          Mar 13 at 11:09





          @ilya1725, well, I just guess that this naming desicion comes from some average practice of Qt container's usage -- it's not an often situation when someone really needs a simple linked list, more likely that someone doesn't want/need QVector, complex server backends is not usually written in Qt, after all =). Thus, QList is multipurpose and efficient for average cases, all classes in designed to be used quickly and easily (like QTcpSocket is not as customizable as real socket, but is very straightforward when used). That's my assumption))

          – MasterAler
          Mar 13 at 11:09



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071969%2fpointer-to-an-element-in-qlist%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

          Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

          How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page