[Development] The future of smart pointers in Qt API

Vitaly Fanaskov vitaly.fanaskov at qt.io
Mon Feb 3 16:26:24 CET 2020


Yes in a current architecture it could be complicated. But if case of 
layouts, ownership is transferred to a layout. Other items might keep a 
weak references to a widget. Removing a widget invalidates all weak 
references. But, again, this only an assumption how it could be implemented.

I actually tend to agree that parent-child relationship model is 
fundamentally wrong, at least as it implemented now. It responsible for 
different things: memory management, event handling, and visual 
positioning. Memory management could be handled by smart pointers, and 
if we really need using trees for two other things, that it should be 
explicit models based on n-ary tree. In this case, I think we won't have 
this confusing definitions like "visual parent" and "just a parent" 
(that we have in controls).

Unfortunately, writing Qt (at least UI part) from scratch might be 
easier than implementing something like that :) Start using smart 
pointers sounds more realistic.

On 2/3/20 3:33 PM, Konrad Rosenbaum wrote:
> On 2020-02-03 15:04, Vitaly Fanaskov wrote:
>> We don't need this method at all if everything is implemented with using
>> smart pointers.
>
> What about the case when I want to delete a Widget from my window 
> without closing the window?
>
> I often use deleteLater() because it is much easier than remembering a 
> dozen layers of layouts and widgets that simply serve some 
> layouting-purpose.
>
>
> Konrad
>
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development

-- 
Best Regards,

Fanaskov Vitaly
Senior Software Engineer

The Qt Company / Qt Quick and Widgets Team



More information about the Development mailing list