[Development] unique_ptr and Qt, Take 2

Иван Комиссаров abbapoh at gmail.com
Fri May 3 22:00:52 CEST 2019


Which should be considered bad practice and banned on an API level

QWidget w2
QWidget w1;
w1.setParent(&w2);

QWidget w1;
QWidget w2
w1.setParent(&w2);

Which one will crash?=)

> 3 мая 2019 г., в 21:40, Thiago Macieira <thiago.macieira at intel.com> написал(а):
> 
> On Friday, 3 May 2019 12:32:01 PDT Allan Sandfeld Jensen wrote:
>> Alternatively QObjects should be referenced counted, one reference could be
>> from a parent, but you could also strong reference with an explicit shared
>> pointer.
> 
> The problem with that is that you can create QObjects on the stack and those 
> mustn't be refcounted.
> 
> That said, the QPointer mechanism since 5.0 is basically refcounting, 
> Technically, it's a refcounted refcounter. Since it shares the same class as 
> QSharedPointer, it *has* the strong refcount inside, which could be used for 
> this.
> 
> -- 
> Thiago Macieira - thiago.macieira (AT) intel.com
>  Software Architect - Intel System Software Products
> 
> 
> 
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> https://lists.qt-project.org/listinfo/development




More information about the Development mailing list