Closed yoo closed 10 years ago
It's because ApplicationWindow is a QWindow and not a QQuickItem QWindow has a method setParent(QWindow) but the ApplicationWindow has no property and this has a whole other meaning than that of QQuickItem's parent and also of QObject. Some info: http://qt-project.org/doc/qt-5.0/qtquick/qtquick-visualcanvas-visualparent.html http://qt-project.org/doc/qt-5.1/qtquick/qquickwindow.html
Chances are high you don't want this.
@labsin is right: when you use a Window or ApplicationWindow as the root of your QML tree, what you get out of window.Root() is not a QQuickItem, so you cannot set the "parent" property of another QQuickItem to it. That's the reason why it crashes. You can fix your code, as described at the bottom, but there's still a bug here: crashing in such a cryptic way is terrible for such a trivial operation.
This was just fixed on commit 7c2a7c6. Now that erroneous logic will crash the application with the following message:
panic: cannot set property "parent" with type QQuickItem* to value of QQuickWindow*
This should hopefully make the problem more obvious.
So, knowing what's wrong, you can fix your code and keep the Window as the root of the QML code. For example, you can declare the QML code along the lines of:
Window {
Rectangle {
objectName: "rect"
}
}
Then, inside your Go code change the parent with:
obj.Set("parent", win.Root().ObjectByName("rect"))
This should achieve the same result of the original example.
I get a segvault when try to add QML Objects to an ApplicationWindow from Go. This can be recreated by modifying the rect.qml from the reparent example.
The segvault occurs when calling obj.Set("parent", win.Root())
Here is a gdb backtrace. The program breaks when calling QQuickItem::parentItem() on the ApplicationWindow.