Results 1 to 4 of 4

Thread: Query about QHash , QList

  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Query about QHash , QList

    I want to know if QHash, QList makes a copy of the items inserted into them or what ??
    Suppose I have a function CreateList()

    Qt Code:
    1. class MyNode
    2. {
    3. int id;
    4. QScene *scene; // pointer to a scene or any other class based on id.
    5. public :
    6. MyNode(QScene *s)
    7. { scene = s;
    8. id = 0; // or some unique value
    9. }
    10. };
    11. QList<MyNode> list;
    12. void CreateList()
    13. {
    14. MyNode node(this->pScene);
    15. list.append(node);
    16. }
    To copy to clipboard, switch view to plain text mode 


    Here I have added just one item, though multiple items may be insterted in the list. I want to know when CreateList function is exited, wll list still have valid copy of node ??

    also what if i have pointers instead of objects..
    like
    Qt Code:
    1. QList<MyNode*> list;
    2. void CreateList()
    3. {
    4. MyNode *node = new MyNode(this->pScene); // node contains some
    5. list.append(node);
    6. }
    To copy to clipboard, switch view to plain text mode 

    in this case how do i delete the actual nodes created. Does list.clear() call the destructor too ?? if not what is the safe way of freeing the memory when a list of pointers is cleared ?

    I think I know the answers, but still a little confused,so asking in the forum, (i know i sound a little stupid here )
    Thx in advance

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Query about QHash , QList

    Lists copies, so if you do not want that - use a pointer list. That way it is the pointer and not the object that is copied.

  3. #3
    Join Date
    May 2006
    Posts
    55
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Query about QHash , QList


  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: Query about QHash , QList

    Thanks to both johan and lauranger

Similar Threads

  1. QList crash in destructor
    By mclark in forum Newbie
    Replies: 7
    Last Post: 6th December 2006, 15:27
  2. QList usage in place QPtrList
    By darpan in forum Qt Programming
    Replies: 2
    Last Post: 25th October 2006, 15:41
  3. Accessing QList Objects
    By magikalpnoi in forum Qt Programming
    Replies: 7
    Last Post: 21st September 2006, 20:43
  4. Aborting a query set on a TableModel
    By Quid in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2006, 22:36
  5. Values not being appended in a QList
    By Kapil in forum Newbie
    Replies: 5
    Last Post: 21st April 2006, 10:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.