[Development] parented_ptr

Ville Voutilainen ville.voutilainen at gmail.com
Fri Oct 17 20:06:39 CEST 2025


On Thu, 16 Oct 2025 at 12:44, André Somers via Development
<development at qt-project.org> wrote:
> Perhaps it might be easier or better to add a make_child template method
> to QObject that returns a new instance of the template type, parented to
> the object you call it on? So you could do something like:
>
> auto button = myDialog->make_child<QPushButton>(tr("Some button"));

+1

> I think it should be possible to specialize these where needed (like in
> this case, where the expected parent is actually a QWidget, not a
> QObject), but I didn't try.

Perhaps it would just be simpler to have a makeChildObject<>() for QObjects
and makeChildWidget<>() for QWidgets.


More information about the Development mailing list