Hello,

I've a QML component that is created from C++ code:

QML code:
Qt Code:
  1. Rectangle {
  2. width: parent.width
  3. y: parent.height / 2
  4. color: "red"
  5. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QQmlComponent component(engine, QUrl(src));
  2. QObject *comp = component.create();
  3. QQuickItem *item = qobject_cast<QQuickItem*>(comp);
  4. item->setParentItem(root);
To copy to clipboard, switch view to plain text mode 

When the component is created appears these errors:

TypeError: Cannot read property 'height' of null
TypeError: Cannot read property 'width' of null

On creation, the parent property is null and not is valid until the item->setParentItem is executed. How can I set the parent item when creating the component? or how to avoid these errors?

Best regards.