SmartPointerList

Thiago Macieira thiago at kde.org
Wed Jan 13 18:35:29 GMT 2010


Em Quarta-feira 13 Janeiro 2010, às 17:06:08, André Wöbbeking escreveu:
> On Wednesday 13 January 2010, Thiago Macieira wrote:
> > Em Quarta-feira 13 Janeiro 2010, às 00:07:01, Ingo Klöcker escreveu:
> > > Thanks a lot for the explanation, Thiago! It's very much
> > > appreciated. I guess tomorrow I'll write a bug to replace all
> > > QPointers by QWeakPointers once we depend on Qt 4.6. (No, I'm not
> > > talking about KDE. :-) )
> > 
> > Remember that QWeakPointer has no operator-> by default.
> > 
> > That's a protection mechanism, because QWeakPointer doesn't guarantee
> > that the pointer will remain valid.
> 
> QPointer also doesn't have that guarantee but it has operator->. What is
> the difference?

It's a matter of preference. QPointer automatically casts to the pointer and 
has ->, so you may never realise you're using a QPointer. That could lead to 
bad code.

QWeakPointer, on the other hand, forces you to add .data(), which makes it 
clear that it's not an actual pointer. When writing the code, you're reminded 
to think "is the pointer guaranteed to be valid here?". And when reading it, 
you're reminded that something else is happening.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20100113/d147c302/attachment.sig>


More information about the kde-core-devel mailing list