Dynamic Qt.createQmlObject with ID
-
Hi,
As you can see below I'm trying to communicate between two : Qt.createQmlObjectIn the 1st I create a "Rectangle" and in the second I create the "Text".
I want the second, that anchored with the rectangl : Anchors.centerInBut it seems he does not see the ID of "Rectangle". Error : Error: Qt.createQmlObject(): failed to create object:
If I erase << anchors.centerIn: "menuId_'+menu[i].id+' " >>, all work fine but the text is on same place.Where did I make a mistake?
Component.onCompleted: { var x=0; var y=0; var titi_debug=0; var menu = JSON.parse(getData('object')); for(var i = 0; i < menu.length; i++) { console.log("JSON Parse: " + menu[i].id); console.log("JSON Parse: " + menu[i].name); Qt.createQmlObject('import QtQuick 2.0; Rectangle {id : "menuId_'+menu[i].id+'"; color: "red"; width: 50; height: 50; x: '+x+'; y:'+y+'}', tuile, "toto"); Qt.createQmlObject('import QtQuick 2.0; Text {id : "textId_'+menu[i].id+'"; text: "'+menu[i].name+'"; color: "white"; anchors.centerIn: "menuId_'+menu[i].id+'"}', tuile, "tata"); y=y+100; titi_debug=x+100; } }
-