3

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) にはプロパティ文字列 title があり、後で Text アイテムのテキスト フィールドに割り当てられます。

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 に割り当てることができません

これを回避する方法はありますか?

4

1 に答える 1

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

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

問題はproperty、タイトル識別子へのバインドと、タイトル識別子へバインドがあることです。出力に基づいて、( ではなく) からテキストを割り当てようとしている可能性があります。ididproperty

コンポーネントの を変更するidText、問題が解決するはずです。

于 2013-04-09T02:55:28.347 に答える