有人知道如何从 C++ 访问和存储动态创建的 QML 对象吗?我使用 Qt Site 上建议的以下代码来创建动态 QML 对象并尝试将它们存储在QML 列表类型中
property list<Button> listButtons: [
Button{ }
]
function addButton(buttonname) {
console.log("Creating Pin: "+buttonname)
var component = Qt.createComponent("Button.qml");
if (component.status == Component.Ready)
{
var newbutton = component.createObject(node);
newbutton.x = 20;
newbutton.y = 30;
listButtons.append(newbutton) //I get a error here: listButtons.append [undefined] is not a function
}
else
{
console.log("Unable to create button: "+buttonname)
}
}
谢谢你。
简历