On Wed, 5 Nov 2025 at 12:11, Volker Hilsheimer via Development <[email protected]> wrote: > And again, we need to make sure that object->createChild<QWidget>() is not > possible; from what I see, that can be solved via SFINAE: > > class QObject … > { > template <typename ChildType, typename ...Args, > std::enable_if_t<!std::is_base_of_v<QWidget, ChildType>, bool> > = true > > > ChildType *makeChild(Args &&...args) > { > return new ChildType(std::forward<Args>(args)..., this); > } > }; > > (it’s enough for QWidget to be forward declared, which it is already in > qobject.h) > > and then overloading this in QWidget without the constraint (a QObject can be > a child of a QWidget).
I don't quite follow why you think you need any SFINAE for this. If you try to construct a QWidget child with a QObject::createChildObject(), that will fail to compile anyway because it tries to pass a QObject* parent to the QWidget constructor, and that constructor takes a QWidget*. There is no implicit base*->derived* conversion. -- Development mailing list [email protected] https://lists.qt-project.org/listinfo/development
