After collecting various information on several posts on StackOverflow, I managed to dynamically create my QML component from some Qt C++ code.
Unfortunately, right after the creation, the QQmlComponent::setProperty method doesn't seem to have any effect. I can see the red rectangle but it doesn't go to x/y position that I want.
Anyone has any idea ?
Maybe there's something wrong on the "x: xPos" "y: yPos" property bindings ?
QML code:
import QtQuick 2.2
Rectangle {
property int xPos: 0;
property int yPos: 0;
width: 100
height: 100
x: xPos
y: yPos
color: "red";
radius: 10
}
C++ code (m_view is a QQuickView):
QQuickItem *twoDView = qobject_cast<QQuickItem*>(m_view->rootObject()->findChild<QObject *>("myView"));
QQmlComponent myComponent(m_view->engine(), QUrl("qrc:/myItem.qml"));
QQuickItem *newView = qobject_cast<QQuickItem*>(myComponent.create());
newView->setParentItem(twoDView);
myComponent.setProperty("xPos", x);
myComponent.setProperty("yPos", y);