[Development] The future of smart pointers in Qt API

Daniel Teske qt at squorn.de
Sun Feb 2 23:30:09 CET 2020


Am 02.02.2020 um 18:17 schrieb Иван Комиссаров:
> Can we please return to the discussion about QObject parent/child with smart pointers rather than discussing Qt/stl naming?
>
> No one answered my question about QObject::deleteLater:
>
>> And what about the QObject::deleteLater() method? Any ideas how this should look like with smart pointers?

So obviously this:

std::unique_ptr<> ptr;
ptr->deleteLater();

should show a warning. Thus, the first step is to annotate deleteLater 
with a optional deprecation.

Then two new functions need to be added:

static QObject::deleteLater(QObject *ptr)

which does not violate that invariant. (Unless you take a pointer out of 
a unique_ptr and pass it in.)

And a second variant:
static QObject::deleteLater(std::unique_ptr<QObject> ptr)

which quite obviously also keeps the invariant.

I think I missed the function in my patch, but that's how you could 
easily do it.

daniel



More information about the Development mailing list