我试图动态地将图片附加到listview
。如果我使用ListElement
并静态指定路径,它会起作用,但如果我尝试在FileDialog.fileUrl.toString()
事件中使用onAccepted
,它会抛出我在标题中提到的错误。文件URL虽然在控制台上成功打印
这是相关代码:
FileDialog {
id: aImage
title: "Please choose a file"
folder: shortcuts.pictures
nameFilters: [ "Image files (*.jpg *.png)", "All files (*)" ]
onAccepted: {
console.log("You chose: " + aImage.fileUrl.toString())
listModel.append({username: "Akash", src: aImage.fileUrl.toString()});
listView.positionViewAtEnd();
}
}
这是ListView的项目委托的Image元素:
Image{
id: image
height: 50
width: 50
source: src
Component.onCompleted: console.log("src: " + src);
}