I have two questions.I am creating an app with Qt. I am using qml and js for my frontend code. I am trying to find a way to create multiple objects dynamically inside a ColumnLayout{}. Lets assume those objects will be rectangles.The server will send me an array with data (images, texts and types) I will calculate array's length and i will add those data to each rectangle. How will i be able to add them into the rectangles? I will try to make the code simple and cut all the unnecessary parts. What you will see it is probably wrong but this was the only thing that came in my mind.
Item {
id:main_container
width: parent.width
height: parent.height
//////////////////////js///////////////////////////////////////
function test(){
var foo = new Array(2);
for(var i = 0; i < foo.length; i++){
console.log("i am here");
var newObject = Qt.createQmlObject('import QtQuick 2.0; Rectangle { color: "red"; border.color: "black"; border.width: 5; width: 150; height: 150}',body);//i noticed Layout.preferedWidth & height here occurs error so i have to use width and height
}
}
////////////////////////////////
Rectangle{
id: home_main_container
anchors.fill: parent
Rectangle{
id:header
width: parent.width
height: parent.height/10
anchors.top: parent.top
color: b1
}
Rectangle{
id:body
width: parent.width
height: parent.height*(8/10)
anchors.top: header.bottom
anchors.horizontalCenter: parent.horizontalCenter
ColumnLayout{
id:body_part1
width: parent.width
height: parent.height/4
anchors.top: parent.bottom
Component.onCompleted: test();
}
}
Rectangle{
id:footer
width: parent.width
height: parent.height/10
anchors.bottom: parent.bottom
color: b1
}
}
}