Qml 创建ComponentDefinition Blackberry 10 Native的新对象实例时应用程序崩溃
我正在使用createObject()创建ComponentDefinition的新对象实例,然后将其添加到容器中。我的应用程序在到达QML中的上述代码行时崩溃 这是我的密码:Qml 创建ComponentDefinition Blackberry 10 Native的新对象实例时应用程序崩溃,qml,blackberry-10,Qml,Blackberry 10,我正在使用createObject()创建ComponentDefinition的新对象实例,然后将其添加到容器中。我的应用程序在到达QML中的上述代码行时崩溃 这是我的密码: import bb.cascades 1.0 import Data.UpdateReservationView 1.0 //a custom C++ qmlRegisterType Page { property alias resDetails: updateRes.resDetails att
import bb.cascades 1.0
import Data.UpdateReservationView 1.0 //a custom C++ qmlRegisterType
Page {
property alias resDetails: updateRes.resDetails
attachedObjects: [
ComponentDefinition {
id: enhLabel
Label {
textStyle.fontSize: FontSize.PointValue
textStyle.fontSizeValue: 5.5
textStyle.color: Color.Black
}
},
UpdateReservationView {
id: updateRes
}
]
onResDetailsChanged: {
// some code
var newLabel = enhLabel.createObject(); //the app crashes upon reaching this line
newLabel.text = resDetails[i]["roomName"];
labelsContainer.add(newLabel);
}
ScrollView {
topMargin: 30.0
horizontalAlignment: HorizontalAlignment.Fill
Container{
leftPadding: 20.0
rightPadding: leftPadding
bottomPadding: 50.0
horizontalAlignment: HorizontalAlignment.Fill
Container {
id: labelsContainer
horizontalAlignment: HorizontalAlignment.Left
verticalAlignment: VerticalAlignment.Center
}
}
} //ScrollView ends
} //Page ends
我尝试过使用.load()
而不是.createObject()
,但得到的结果与组件定义(enhLabel)在代码中的其他地方实例化的结果相同,根据我的理解。load()只需加载一次控件,而我需要动态地多次创建它的新实例
奇怪的是,代码在前一天运行得非常完美,而我在这个特定的QML文件中没有做任何更改。
应用程序崩溃的原因可能是什么。我确信它在使用老式的console.debug()方法到达
var newLabel=enhlab.createObject()行时崩溃 不确定您这边发生了什么变化,但根据上的代码示例,我可以看到您的代码看起来不错:
Container {
Button {
text: "Click to create bordered text"
onClicked: {
// Creates borderedTextComponent control and appends it
// to the container
var createdControl = borderedTextComponent.createObject();
container.add(createdControl);
createdControl.textString = "Hello Component";
createdControl.padding = 30;
createdControl.textColor = Color.DarkGray;
}
}
Container {
id: container
}
attachedObjects: [
ComponentDefinition {
id: borderedTextComponent
Container {
property variant borderColor: Color.Red
property variant fillColor: Color.White
property variant textColor: Color.Black
property string textString
property real padding: 10;
background: borderColor
leftPadding: padding
rightPadding: padding
topPadding: padding
bottomPadding: padding
Container {
background: fillColor
Label {
text: textString
textStyle.color: textColor
}
}
}
}
]
}
也许可以尝试一下这个示例,看看您是否有环境问题,这个问题在一个标准的空Cascades项目中对我有效,并将代码粘贴到页面{}中
不幸的是,您的代码中有太多内容丢失,无法重现我这边的崩溃