[Qt-interest] About QScopedPointer
Mihail Naydenov
mlists at ymail.com
Fri May 13 12:33:45 CEST 2011
----- Original Message ----
> From: Thiago Macieira <thiago at kde.org>
> To: qt-interest at qt.nokia.com
> Sent: Fri, May 13, 2011 12:39:55 PM
> Subject: Re: [Qt-interest] About QScopedPointer
>
> On Friday, 13 de May de 2011 00:47:56 Mihail Naydenov wrote:
> > I am in a bit of a struggle how to pass a pointer to a
> > QScopedPointer-managed pointer.
> > It seems impossible:
> >
> > QScopedPointer<Data> d;
> >
> > fund(void** data); //< want to pass d into this
>
> No, you don't.
>
> You have a QScopedPointer<Data>, which is equivalent to Data*. One level of
> pointer.
>
> That function takes a void**: two levels of pointers.
>
> If you had a simple Data *d; you'd pass &d. That usually means that the called
>
> function would modify the pointer.
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
>
> That's a really bad idea with QScopedPointer. It owns the pointer and you
> should not modify the value from underneath it.
>
> > I guess QScopedPointer lacks a T*& data() member function. Is this going to
> > be addressed. Or am I missing something.
>
> No, it's not going to be addressed. That method can only be used to allow you
> to modify the pointer that QScopedPointer tracks without telling it.
>
> You chose to use QScopedPointer so it would manage the pointers for you.
>
> --
> 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