[Qt-interest] About QScopedPointer

Mihail Naydenov mlists at ymail.com
Fri May 13 17:10:28 CEST 2011


----- Original Message ----

> From: Thiago Macieira <thiago at kde.org>
> To: qt-interest at qt.nokia.com
> Sent: Fri, May 13, 2011 4:33:00 PM
> Subject: Re: [Qt-interest] About QScopedPointer
> 
> On Friday, 13 de May de 2011 03:33:45 Mihail Naydenov wrote:
> > Problem is  sometimes the pointer is not initialized when constructed.
> > 
> > It  is later initialized by some func(Data** data)
> > 
> > Now I will have  to do
> > 
> > Data* p = NULL;
> > 
> > func(&p);
> > 
> > QScopedPointer<Data, Release> sp(p);
> > 
> > // use sp,  forget about p
> > 
> > Which is a bit cumbersome
> 
> Indeed. But  you're attacking this problem from the wrong angle. You should 
> change func  to be:
> 
>     func(QScopedPointer<Data>  &p)
> 
> So you can just do:
>      QScopedPointer<Data> d;
>     func(d);

Its is not my function, of course. It is COM's CoCreateInstance()

> 
> -- 
> 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
> 



More information about the Qt-interest-old mailing list