[Development] The future of smart pointers in Qt API

Daniel Teske qt at squorn.de
Tue Feb 4 19:40:39 CET 2020


Am 04.02.2020 um 07:53 schrieb Shawn Rutledge:
>
>> On 1 Feb 2020, at 19:20, Daniel Teske <qt at squorn.de 
>> <mailto:qt at squorn.de>> wrote:
>>
>> Now to take your next example: setParent is not fine. setParent can 
>> be used in 4 different ways:
>>
>> child->setParent(child->parent()): Invariant holds
>> child->setParent(newParent): Invariant holds
>> child->setParent(nullptr): Nope
>> orphan->setParent(parent): Nope
>>
>> The solution is I have is to replace setParent with two functions: 
>> adoptChild + releaseChild, which both ensure that the invariant 
>> always holds.
>>
>> And to deprecate setParent. ...
>>
> In Qt Quick we plan to have a unified ownership tree in Qt 6: visual 
> parent item will be the same as QObject parent.  (Whereas in Qt 5, 
> QQuickItem::setParentItem() sets a different pointer.)  And 
> Item.parent is a property, so it’s expected to be able to reparent a 
> subtree of Items by setting its parent to a different one.  How do you 
> think that should be handled?
>
You snipped out the relevant part that explains that there are new 
methods: adoptChild + releaseChild. So I don't see any problem?

daniel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200204/861c3b9a/attachment-0001.html>


More information about the Development mailing list