[Development] The future of smart pointers in Qt API

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Sun Feb 2 19:39:55 CET 2020


On 02/02/2020 18:17, Иван Комиссаров wrote:
> 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?

You can specify custom deleters for smart pointers. For QScopedPointer 
there's already a convenience class that does it:

> QScopedPointer<MyObject, QScopedPointerDeleteLater> ptr = ~~~;
> // ptr falls out of scope, deleteLater() is called on the pointee

Such a convenience deleter should be moved to QObject, to be honest (and 
no, it's not usable as-is with std:: smart pointers).

Note: I didn't review Daniel's proposal so I'm not sure if this would 
actually work in there.

HTH,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4329 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200202/505ceca9/attachment.bin>


More information about the Development mailing list