PDA

View Full Version : setAutoDelete(bool) in Qlist



vishal.chauhan
18th January 2007, 11:33
Hi all,

I m using QT 4.2.2 on my Intel Mac.
Earlier I m using Qt 3.3 in which I have used the function setAutoDelete(bool) of QPtrList.
Now I m using QList in Qt 4.2.2 in which I cannot use QPtrList so I m using QList instead of that.

Now how can I use the setAutoDelete function of QListPtr in Qlist or there is osme other function in Qt 4.2.2 for that.

Thanks.

wysota
18th January 2007, 11:50
qDeleteAll()

jpn
18th January 2007, 11:52
Porting to Qt 4 - QPtrList<T> (http://doc.trolltech.com/4.2/porting4.html#qptrlist-t)

If you use QPtrList's auto-delete feature (by calling QPtrList::setAutoDelete(true)), you need to do some more work. You have two options: Either you call delete yourself whenever you remove an item from the container, or you can use QList<T> instead of QList<T *> (i.e. store values directly instead of pointers to values).

qDeleteAll() from QtAlgorithms (http://doc.trolltech.com/4.2/qtalgorithms) might be handy..

vishal.chauhan
18th January 2007, 12:41
Thanks.

But I donot know how to use it.
QList<TREEITEM *>list;
When I m using this like
list.qDeleteAll()
then it is giving error that QList<TREEITEM *> has no member name qDeleteAll().

Plz describe how I can use it.

Thanks.

jacek
18th January 2007, 12:43
But I donot know how to use it.
QList<TREEITEM *>list;
When I m using this like
list.qDeleteAll()
then it is giving error that QList<TREEITEM *> has no member name qDeleteAll()
qDeleteAll() is a function, so you call it like this:
qDeleteAll( list );

vishal.chauhan
18th January 2007, 13:03
Thanks to all of you.
Now I m using this function.

Glitch
19th January 2007, 02:50
You can also emulate autoDelete when removing items one at a time:

instead of list.remove(i) use

delete list.takeAt(i);

--Justin