我正在尝试在 qml-javascript 中动态创建对象。创建对象的函数是:
function createSpriteObjects(xPos,yPos,cnt,imgsrc,jsonObject) {
var title;
title = jsonObject.matches[cnt].recipeName;
var component = Qt.createComponent("FlickItem.qml");
component.createObject(wall.contentItem, {"color":"white", "x":xPos,"y":yPos,"src":imgsrc,"opacity":1,"title":title});
}
接收文件 (FlickItem.qml) 有一个属性字符串标题,稍后将其分配给文本项的文本字段:
import QtQuick 2.0
Rectangle {
id: name
opacity: 0
property string title: ""
width:100
height:100
color:"white"
property string src: ""
Image {
id:recipeimages
source: src
width:240
height:160
}
Text {
id: title
anchors.bottom: recipeimages.bottom
anchors.horizontalCenter: recipeimages.horizontalCenter
anchors.bottomMargin: 5
color: "white"
font.pixelSize: 24
text:title
}
返回以下错误:
无法将 QQuickText 分配给 QString
有什么办法吗?