从 C++ 访问动态 QML 对象
有谁知道如何访问和存储从 C++ 动态创建的 QML 对象? 我使用 Qt 网站上建议的以下代码来创建动态 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)
}
}
谢谢。
简历
Is anyone aware of how to access and store dynamically created QML objects from C++?
I used the following code suggested on Qt Site for creating dynamic QML objects and trying to store them in a QML list type
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)
}
}
Thank you.
CV
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有关于此的文档。 http://doc.qt.nokia.com/4.7/qml-list.html
要实现此目的,您需要
未经测试的代码中将数组实现为列表script.js
从 c++
。
嗯,我对此不确定。但也许 QVariant.toList() 会起作用,也可能不会。你必须尝试一下。
There is documentation regarding this. http://doc.qt.nokia.com/4.7/qml-list.html
To achieve this you need to implement an array as a list
script.js
from c++
Untested code.
hmmm, i am not sure about this.But maybe QVariant.toList() will work or maybe it wont.You'll have to try.