[Development] parented_ptr
Volker Hilsheimer
volker.hilsheimer at qt.io
Thu Oct 30 20:55:20 CET 2025
> On 30 Oct 2025, at 18:20, Daniel Schürmann <daschuer at mixxx.org> wrote:
>
> 3: QObject::addChild(std::unique_ptr<QObject *> child)
> Will this have a chance to being merged upstream?
In principle, I don’t see a reason why this would not be acceptable.
The devil is in the details; note that the following does not compile:
QObject parent;
QWidget widget;
widget.setParent(&parent);
as QWidget::setParent(QWidget *) shadows QObject::setParent(QObject *). The equivalent code using addChild
QObject object;
auto child = std::make_unique<QWidget>();
object.addChild(std::move(child));
should also not compile, as a QWidget must only have another widget as the parent.
(and thinking about it, that’s also something to keep in mind for QObject::makeChildObject).
And all of that without qobject.h being able to include qwidget.h… which might make this challenging.
Volker
More information about the Development
mailing list