首页 > 学院 > 开发设计 > 正文

QML的createQmlObject()函数参数传递和函数传递

2019-11-06 07:40:14
字体:
来源:转载
供稿:网友
var src = "import QtQuick 2.0 Rectangle{ anchors.fill: parentItem; color: /"transparent/" " for (var i = 0; i < pageCount*2; i++) { console.log("test test test 1111111"); src += " Image{ anchors.fill: parent; visible: /"%1/" < /"%2/"? false:/"%3/" === /"%4/"? true:false; source: /"%5/" } Binding{ target: parent; PRoperty: /"source/"; value:/"%6/"; } ".arg(pageCount).arg(parseInt(i/2)+1).arg(parentItem.source).arg(i+1).arg("file:///root/active/image/"+sourcePath+String(i+1)+".png") } src += "}" var model = Qt.createQmlObject(src, parentItem, "dynamicImage")

上述代码,可以实现在qml中动态显示图片,所创建的动态的qml文件参数的传递,如上述所示,这是一种方法,

下述描述,在采用Qt.createQmlObject()函数加载qml文件的时候,所加载的qml包含函数的使用方法,和上述有点区别

var idx = 21;var img = Qt.createQmlObject("import QtQuick 2.0; Image{property int idx;anchors.fill:parent}",item,"dynaImage");img.idx = idx;img.visible = Qt.binding(function(){});

//注意:在函数中的使用变量idx的时候,如果只创建一个,则可以直接使用id.idx,如果是创建多个则不可直接使用id.idx变量,需要使用this指针进行识别,否则会出现创建多个item,每个的item的idx值都会变成最后一个item的值


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表