[Development] The future of smart pointers in Qt API

Ville Voutilainen ville.voutilainen at gmail.com
Sun Feb 2 21:25:42 CET 2020


On Sun, 2 Feb 2020 at 19:19, Иван Комиссаров <abbapoh at gmail.com> wrote:
>
> 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?

For a unique_ptr, a deleteLater would take ownership and destroy the
moved unique_ptr on a different event loop round,
for a shared_ptr, a deleteLater would copy it and destroy the copy on
a different event loop round. The difference is
that you can't touch a unique_ptr after a deleteLater call, and if you
happen to hold on to a copy of the shared_ptr,
the deletion might not occur at all.


More information about the Development mailing list