[Qt-interest] About QScopedPointer
Mihail Naydenov
mlists at ymail.com
Sun May 15 18:52:51 CEST 2011
struct IUnknownRelease
{
static inline void cleanup(IUnknown* p)
{
if(!p)
return;
p->Release();
}
};
QScopedPointer<IamComInterface, IUnknownRelease> sp(p);
;)
----- Original Message ----
> From: Constantin Makshin <cmakshin at gmail.com>
> To: Qt Interest <qt-interest at qt.nokia.com>
> Sent: Sun, May 15, 2011 7:24:21 PM
> Subject: Re: [Qt-interest] About QScopedPointer
>
> AFAIR, all COM objects are meant to be destroyed using their Release()
method
>and not C++'s "delete" operator. So using QScopedPointer doesn't seem to be a
>[very] good idea.
>
> On Friday 13 May 2011 19:10:28 Mihail Naydenov wrote:
> > ----- 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()
>
More information about the Qt-interest-old
mailing list