[Development] parented_ptr
Ville Voutilainen
ville.voutilainen at gmail.com
Mon Nov 3 16:59:08 CET 2025
On Mon, 3 Nov 2025 at 17:52, Ville Voutilainen
<ville.voutilainen at gmail.com> wrote:
> > the workaround is the rather ugly:
> >
> > parent.createChild<QObject>(&parent);
>
> That's not needed at all.
See, the reason is that QObject parents aren't of type
SomeTypeInheritingQObject. They are QObjects.
That's why we don't need to deduce the parent type (which we can do
since C++23, but we don't need to go to that here),
and QObject works for the parent type.
Same goes for QWidgets.
You can of course pass whatever derived type pointer as the parent
argument, it will just get implicitly converted to a pointer
to the base type.
More information about the Development
mailing list