[Qt-interest] About QScopedPointer

Anton Chernov mechernov at gmail.com
Fri May 13 12:07:34 CEST 2011


fund( &( d->data() ) );

am i evil?

2011/5/13 Thiago Macieira <thiago at kde.org>

> 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.
>
> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110513/8eed5849/attachment.html 


More information about the Qt-interest-old mailing list