Results 1 to 3 of 3

Thread: QValueList, how to remove and free allocated memory

  1. #1
    Join Date
    Jan 2006
    Posts
    162
    Thanks
    9
    Qt products
    Qt3
    Platforms
    Windows

    Default QValueList, how to remove and free allocated memory

    Hi,

    I have a class that has a member of type
    Qt Code:
    1. QValueList<AClassOfMine*> list
    To copy to clipboard, switch view to plain text mode 

    and a function
    Qt Code:
    1. void addClass(AClassOfMine value)
    To copy to clipboard, switch view to plain text mode 
    This function do only the two following lines of code
    Qt Code:
    1. AClassOfMine* myClass = new AClassOfMine(value);
    2. list.append(myClass);
    To copy to clipboard, switch view to plain text mode 

    How can I remove and free all elements in my list ?

    For the moment I just do
    Qt Code:
    1. list.clear()
    To copy to clipboard, switch view to plain text mode 
    but I expect some memory leaks to soon come.

    So, how can I solve my problem ?

    Thanks in advance

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

    Default Re: QValueList, how to remove and free allocated memory

    Use QPtrList instead of QValueList and set AutoDelete to true.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 975 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QValueList, how to remove and free allocated memory

    In Qt3 you can use QPtrList with setAutoDelete( true ).

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.