Results 1 to 4 of 4

Thread: How to delete QMap ?

  1. #1
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default How to delete QMap ?

    I have a container like QMap<float, QList<QPair<float,float> *> *> *data, but I can't delete it.
    How to solve this problem?

    My code :

    {
    QMapIterator<float, QList<QPair<float,float> *> *> iterator(*data);
    while(iterator.hasNext()) {
    iterator.next();
    QList<QPair<float,float> *> *timeValues = iterator.value();
    qDeleteAll(*timeValues);
    timeValues->clear();
    }
    qDeleteAll(*data);
    data->clear();
    delete data;
    data = NULL;
    }

    but it doesn't work, at least the memory is not given back to OS immediately.
    Last edited by lwz; 28th September 2014 at 10:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to delete QMap ?

    The memory will not be deallocated from the process immediately, that's a normal thing in modern operating systems.

    And why are you keeping a pointer to a QList in the map instead of QList itself?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2013
    Posts
    72
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: How to delete QMap ?

    Thanks , if I change it to QMap<float, QList<QPair<float,float>>> *data,
    Would it be deallocated immediately?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to delete QMap ?

    No, if you change it to 20 year old operating system then maybe it will. But if you remove the pointer from the data structure you will not have to manually delete each value in the map.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Proper way to delete a QMap
    By jano_alex_es in forum Newbie
    Replies: 4
    Last Post: 28th February 2020, 17:31
  2. Delete item from QMap<int, QString> with shift
    By Usernаme in forum Newbie
    Replies: 1
    Last Post: 24th May 2010, 18:50
  3. QMap
    By sophister in forum Qt Programming
    Replies: 5
    Last Post: 25th May 2009, 10:05
  4. Replies: 4
    Last Post: 19th February 2009, 11:10
  5. How to use QMap::remove() to delete some item?
    By jedychen in forum Qt Programming
    Replies: 5
    Last Post: 18th September 2008, 07:29

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.