[Development] The future of smart pointers in Qt API

André Pönitz apoenitz at t-online.de
Tue Feb 4 23:09:42 CET 2020


On Tue, Feb 04, 2020 at 10:10:08PM +0200, Ville Voutilainen wrote:
> On Tue, 4 Feb 2020 at 21:31, André Pönitz <apoenitz at t-online.de> wrote:
> > Seriously, *double deletion*? In real, proper Qt-style code?
> 
> Yes, seriously, because allocated objects are stored in RAII handles

A "Qt style" "RAII handle" is a QObject parent at creation time.
There is no double deletion in this context, *only* when you start
to sprinkle in other ownership models, i.e. deviate from "Qt style".

> so as to avoid leaking them on break/return/throw (or heaven forbid, goto).
> Then you can pass the result of a .release()  into Qt's various object chains.
> Or if you think shared_ptr is what's needed, then you can't.
> 
> > The only problem is with people passing out when seeing different numbers of 'new'
> > and 'delete'. And it's only a *real* problem when do not they take "Relax, it's ok"
> > as an answer, and start to actively interfere. And that's when double deletion
> > comes into play.
> 
> Indeed. All libraries and frameworks are perfectly fine for everybody,
> as long as they know what they're doing.

Well, no. Some also suck in case one knows what one is doing. OTOH, at 
least roughly knowing what one's doing is probably necessary for any
kind of code.

> > > > If you understand Qt (and don’t assume that by understanding some basic C++
> > > > concepts you can use any framework), then you see that widgets are added to a
> > > > layout that is used, and are therefore managed objects.
> > > Managed by what? Also, it seems downright detrimental if understanding basic C++
> > > concepts is useless with Qt.
> >
> > I don't think that's received as much of an insult as you meant it to be
> > by parts of your audience. Not requiring the verbosity of "basic C++" in
> > user code is surely a benefit of Qt for me, and if people are appalled by
> > not getting that with Qt, well, not my problem.
> 
> Yeah, well, "basic C++" isn't verbose.
> QVector and QList are slightly above basic C++, since they're templates.

Ok? Then what were you referring to when saying "it seems downright detrimental
if understanding basic C++ concepts is useless with Qt."? I thought it was
std::unique_ptr, but that's a template, i.e. no "basic C++" in your definition.

> Yet we don't suggest that users should manually iterate through their elements
> to clean those elements up when no longer needed, but for some reason when
> exactly that technique is suggested to be used in object trees, some of us just
> balk, and start throwing tantrums.

Now you completely lost me. What iteration is suggested to be used to clean
elements in a _QObject_ tree? 

Andre'


More information about the Development mailing list