Results 1 to 5 of 5

Thread: memory leaks and deleting a QMap

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,329
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: memory leaks and deleting a QMap

    More like this:

    Qt Code:
    1. QList< Something * > things = a_map.values();
    2. foreach( Something * thing, things )
    3. {
    4. delete thing;
    5. }
    To copy to clipboard, switch view to plain text mode 

    Edit: although upon reading the docs, it looks like your code would accomplish the same thing. I am more familiar with std:: map<>, where the iterator returns an std:: pair<> containing the key and value.
    Last edited by d_stranz; 13th November 2015 at 22:13.

  2. The following user says thank you to d_stranz for this useful post:

    ravas (14th November 2015)

  3. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: memory leaks and deleting a QMap

    Quote Originally Posted by d_stranz View Post
    Edit: although upon reading the docs, it looks like your code would accomplish the same thing.
    Definitely iterating over the map.
    Iterating over the values requires two iterations: one for creating the list of values and the the actual loop.

    In any case: http://doc.qt.io/qt-5/qtalgorithms.html#qDeleteAll-1

    Cheers,
    _

  4. The following 2 users say thank you to anda_skoa for this useful post:

    d_stranz (16th November 2015), ravas (15th November 2015)

Similar Threads

  1. Memory leaks!
    By karlkar in forum Newbie
    Replies: 1
    Last Post: 28th June 2013, 22:37
  2. Memory Leaks
    By kaushal_gaurav in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2008, 16:26
  3. Memory leaks..
    By santhoshv84 in forum Qt Programming
    Replies: 2
    Last Post: 28th August 2008, 19:28
  4. creating/deleting Objects // memory leaks
    By janus in forum Qt Programming
    Replies: 4
    Last Post: 27th March 2008, 18:17
  5. memory leaks
    By Fastman in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2008, 08:00

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.