2013-04-08 56 views
0

我試圖動態地創建在其中創建對象QML-javascript.The函數對象是:無法QQuickText分配到QString的

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}); 
} 

的recieving文件(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

任何方法可以解決這個問題嗎?

回答

6
Rectangle { 
id: name 
//... 
property string title: "" <------ title 
//... 
} 

Text { 
    //... 
    id: title <----- title 
    //... 
    text:title <---- which title ?!?!?! 
} 

的問題是你有一個property綁定到標題標識,並綁定到標題標識符的id。根據您的輸出,你很可能試圖從id(而不是property)指定的文本。

改變你Text組件的id應該解決您的問題。