[Development] QML, Widgets, and setParent

Konrad Rosenbaum konrad at silmor.de
Thu Nov 7 08:34:24 CET 2013

On Tuesday 05 November 2013 06:48:11 Alan Alpert wrote:
> I'm surprised this works. There's implicit QObject parenting built
> into the language, for example:
> QtObject {
>      id: foo
>      property Widget bar: Widget{}
> }
> Will automatically make foo the qobject parent of bar.

Correct, this example aborts. But not where you expect: it is caught in the 
DeclarativeWidgets lib itself.

$ ./declarativewidgets test.qml 
Root Element is neither an AbstractDeclarativeObject nor a widget

> I'm not certain, but I think this happens before it gets assigned to
> the property which might make any declarative widgets example using
> layouts crash in debug builds...

There is a lot of code handling layouts specially.

If I reformat your example thusly:
import QtWidgets 1.0

Widget {
  HBoxLayout {
     id: foo
     property Widget bar: Label{ text: "hello" }
     Label { text: "world" }

The "world" label shows up, while the "hello" widget is ignored by the layout 
(the outer Widget is necessary because layouts cannot be shown on their own).

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

More information about the Development mailing list