[Development] The future of smart pointers in Qt API
Shawn Rutledge
Shawn.Rutledge at qt.io
Tue Feb 4 07:53:59 CET 2020
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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200204/6a1001cc/attachment.html>
More information about the Development
mailing list