[Development] The future of smart pointers in Qt API

Ville Voutilainen ville.voutilainen at gmail.com
Tue Feb 4 21:10:08 CET 2020


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
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.

> > > 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.
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.


More information about the Development mailing list