[Qt-interest] About QScopedPointer
Thiago Macieira
thiago at kde.org
Fri May 13 11:39:55 CEST 2011
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110513/32e0785f/attachment.bin
More information about the Qt-interest-old
mailing list