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

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme