PDA

View Full Version : QValueList, how to remove and free allocated memory



yellowmat
13th February 2006, 16:15
Hi,

I have a class that has a member of type

QValueList<AClassOfMine*> list

and a function

void addClass(AClassOfMine value)
This function do only the two following lines of code


AClassOfMine* myClass = new AClassOfMine(value);
list.append(myClass);


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

For the moment I just do

list.clear()
but I expect some memory leaks to soon come.

So, how can I solve my problem ?

Thanks in advance

wysota
13th February 2006, 16:41
Use QPtrList instead of QValueList and set AutoDelete to true.

jacek
13th February 2006, 16:42
In Qt3 you can use QPtrList with setAutoDelete( true ).