[Development] QML, Widgets, and setParent

Konrad Rosenbaum konrad at silmor.de
Sat Nov 2 14:45:47 CET 2013

On Saturday 02 November 2013, Kevin Krammer wrote:
> The Qt4 code does not call setParent if the object is a widget and the
> parent is not, e.g. if the parent is a layout. Still seems to work quite
> well.
> Maybe it would still work if the Qt5 code did something like this:
> if (!o->isWidgetType)
>     QQml_setParent_noEvent(o, parent);

wow! You are absolutely correct. It works now.

> > The code of QObject::setParent itself is absolutely identical (I didn't
> > check all the lines of QObjectPrivate::setParent_helper though). Qt4
> > contains the same Q_ASSERT.
> Sure, what I was saying is that maybe it "works for me" because I am
> using a release built Qt4. Q_ASSERT is not part of release build object
> code.

No, I'm using a debug build of Qt4 and it works with that too. The idea 
above was the one that hit it.

I basically restored Qt4 behavior to Qt5, but with a plugin to avoid the 
QtWidgets dependency.

> The thing is that the widgets wouldn't have non-Widget parents, at least
> not in DeclarativeWidgets. The parent is either a widget or, most of the
> times, a layout. The layouts' addWidget methods reparent to their parent
> widget.
> Therefore one option might be to just not call set parent on widget
> objects and let the list property code deal with reparenting.

Yepp. That's it.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 588 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131102/fb78ff72/attachment.sig>

More information about the Development mailing list