首页| 论坛| 消息

标题:QML采用动态方式创建对象遇到复杂类型属性提示Component not ready
作者:彩阳
日期:2014-04-29 12:54
内容:

问题是这样的,我想用动态创建的方式在Javascript函数中创建QML对象。这是一个简单的例子:
// Block.qml
Item
{
id: block
property list imageSources;
……
}
当我使用:
var Block = Qt.createComponent( "Block.qml" );
var block = Block.createObject( parent );
的时候,执行提示QQmlComponent: Component is not ready。
可是去掉了list imageSources这样的属性后就能够顺利地创建Component。我怀疑是因为imageSources是复杂类型(引用类型)导致的。采用了其它的object类型作为属性也会出现同样的问题。
想知道大家遇到了这样的情况究竟是如何解决的。


#1 [toby520 04-29 13:56]
呵呵,qml写的太复杂了,我好像写了这么久还没有用到过这么复杂的类型
#2 [wayne 04-29 18:31]
用javascript语法类型吧:
property var theArray: new Array()
#3 回 wayne 的帖子 [彩阳 04-29 19:00]
wayne:
用javascript语法类型吧:
property var theArray: new Array()
不行吧。QML里面的属性都是静态的,怎能使用javascript的语法呢?
下面是错误截图:
#4 [彩阳 04-29 19:00]
与这个帖子联动一下。
#5 [wayne 04-29 19:15]
Item {
property var theArray: new Array()
property var theDate: new Date()
Component.onCompleted: {
for (var i = 0; i < 10; i++)
theArray.push("Item " + i)
console.log("There are", theArray.length, "items in the array")
console.log("The time is", theDate.toUTCString())
}
}

<< 1 2 >> (1/2)

回复 发表
主题 版块