使用 qt 5.2,我正在尝试动态添加一个简单的按钮,如下所示:
ApplicationWindow
{
id: appWindow
width: 640
height: 420
minimumHeight: 400
minimumWidth: 600
function addButton() {
var obj = Qt.createComponent("Button.qml");
if (obj.status == obj.Ready)
{
var button = obj.createObject(appWindow);
button.color = "red";
button.width=50;
button.height=80;
button.x=50; button.y=50;
}
}
Button {
anchors.centerIn: parent;
text: "ok";
onClicked: {
addButton();
}
} ...
但就在 createComponent 之后,我总是得到:
QQmlComponent:组件没有准备好
怎么了 ?