[Development] unique_ptr and Qt, Take 2
Thiago Macieira
thiago.macieira at intel.com
Fri May 3 20:24:07 CEST 2019
On Friday, 3 May 2019 10:22:20 PDT Daniel Teske wrote:
> std::unique_ptr<QPushButton> rightButton =
> std::make_unique<QPushButton>("RIGHT");
> layout->addWidget(std::move(rightButton));
The problem in this particular example is that once you've added the widget,
the rightButton smart pointer no longer has a pointer. You can't continue to
set up your push button. In most cases, this is just a matter of moving the
set up before the addition / reparenting, or using the other idiom where the
object is never in a smart pointer in the first place.
So this begs the question of whether std::unique_ptr is the best smart pointer
for this scenario. Would it make sense to create one that understands parent-
child relationship?
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel System Software Products
More information about the Development
mailing list