From kde-devel Sat Oct 22 06:36:43 2005 From: Sascha Cunz Date: Sat, 22 Oct 2005 06:36:43 +0000 To: kde-devel Subject: Re: Problem with QT Message-Id: <200510220836.44123.sascha.cunz () tiscali ! de> X-MARC-Message: https://marc.info/?l=kde-devel&m=112997104324502 MIME-Version: 1 Content-Type: multipart/mixed; boundary="--===============1426504528==" --===============1426504528== Content-Type: multipart/alternative; boundary="Boundary-00=_83dWDzJBXqVwrQ4" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-00=_83dWDzJBXqVwrQ4 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Hi, Am Samstag 22 Oktober 2005 09:27 schrieb Bernd Brandstetter: > On Saturday 22 October 2005 00:46, David Faure wrote: > > > And for a perhaps more useful answer, add a destructor for > > > KgpgListKeys that iterates over its keys and deletes them. You might > > > not be able to use foreach() since the dtor will be iterating over > > > itself but something like this would work: > > > > > > KgpgListKeys::~KgpgListKeys() > > > { > > > for(ConstIterator it = constBegin(); it != constEnd(); ++it) > > > { > > > delete *it; > > > } > > > > qDeleteAll(this) should do the same as the above code. > > But be very careful when putting this in the destructor. If somebody > iterates this list using foreach(), he will end up with all elements being > deleted after the loop - which is most probably not what he expected. Unless you talk about multithreading, what you say, would look in code like: foreach( T t, *list ) if( t.foo ) delete list; I'd say: If somebody does that, well then he has to expect the list to get invalid. Cheers Sascha --Boundary-00=_83dWDzJBXqVwrQ4 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit

Hi,

Am Samstag 22 Oktober 2005 09:27 schrieb Bernd Brandstetter:

> On Saturday 22 October 2005 00:46, David Faure wrote:

> > > And for a perhaps more useful answer, add a destructor for

> > > KgpgListKeys that iterates over its keys and deletes them. You might

> > > not be able to use foreach() since the dtor will be iterating over

> > > itself but something like this would work:

> > >

> > > KgpgListKeys::~KgpgListKeys()

> > > {

> > > for(ConstIterator it = constBegin(); it != constEnd(); ++it)

> > > {

> > > delete *it;

> > > }

> >

> > qDeleteAll(this) should do the same as the above code.

>

> But be very careful when putting this in the destructor. If somebody

> iterates this list using foreach(), he will end up with all elements being

> deleted after the loop - which is most probably not what he expected.

Unless you talk about multithreading, what you say, would look in code like:

foreach( T t, *list ) if( t.foo ) delete list;

I'd say: If somebody does that, well then he has to expect the list to get invalid.

Cheers Sascha

--Boundary-00=_83dWDzJBXqVwrQ4-- --===============1426504528== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline >> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe << --===============1426504528==--