QtQuick-FolderListModel未显示所有文件
我在使用FolderListModel时遇到了麻烦。我试图只过滤特定目录的XML文件,并在ListView中显示它们。问题是,它只显示一个文件,而我在这个目录中有几个XML文件。 我尝试使用其他类型的文件(txt、pdf),但它在ListView中从未显示正确数量的文件。 这是我的代码,我做错了什么QtQuick-FolderListModel未显示所有文件,qt,qtquick2,qt-quick,Qt,Qtquick2,Qt Quick,我在使用FolderListModel时遇到了麻烦。我试图只过滤特定目录的XML文件,并在ListView中显示它们。问题是,它只显示一个文件,而我在这个目录中有几个XML文件。 我尝试使用其他类型的文件(txt、pdf),但它在ListView中从未显示正确数量的文件。 这是我的代码,我做错了什么 ListView { id: listView1 x: 0 width: 288 height: 25
ListView {
id: listView1
x: 0
width: 288
height: 256
anchors.top: parent.top
anchors.topMargin: 16
anchors.horizontalCenter: parent.horizontalCenter
delegate: listviewdelegate
model: listviewmodel
clip: true;
}
FolderListModel{
id:listviewmodel
nameFilters: ["*.xml"]
showDirs: false
showDotAndDotDot: false
folder:"C:/Users/bg/Documents"//serializationpath
}
Component{
id:listviewdelegate
Text {
text: fileName
color: m_colorDefault
font.pixelSize: m_iFontSizeMin
anchors.verticalCenter: parent.verticalCenter
}
}
我们不能在ListView中使用FolderListModel吗?
谢谢你的帮助
问候
编辑:
当我试图解决我的问题时,我注意到Qt文档
对于文件夹属性不正确。它说默认情况下它是一个无效的URL,但是如果我没有设置文件夹,它将使用应用程序的文件夹。
我尝试使用绝对路径设置文件夹属性:
FolderListModel {
id: listviewmodel
folder: "F:/QtDev/Sources.ScenarioEditor"
}
但它会继续使用应用程序的文件夹,而不会对错误路径大喊大叫。所以我在这里有点困惑
编辑2:
我终于成功地找到了正确的文件夹,但现在我面临着nameFilters属性的愚蠢行为
以下是一个片段:
FolderListModel {
id: listviewmodel
showDirs: false
//works fine and filters XML
// folder:"file:/F:/QtDev/Sources.ScenarioEditor"
// nameFilters: ["*.xml"]
//works fine but doesn't filter XML
folder:"file:/"+scenario.serializationPath
nameFilters: ["*.xml"]
}
scenario.serializationPath以我的用户文件夹为目标,这是我真正需要使用的文件夹。但在这种情况下,文件过滤不起作用:/
任何帮助都将不胜感激,因为我在这个问题上陷入了一段时间
关于我在尝试将FolderListModel与动态的
文件夹
名称和名称过滤器
一起使用时,遇到了类似的问题。我试图更新文件夹和/或过滤器,然后使用Component.onCompleted
刷新附加到模型的视图。填充模型似乎是一个异步操作,组件未准备好数据。onCompleted
调用,因此作为一种解决方法,我触发了FolderListModelcount
值的视图更新:
property int totalFileCount: folderListModel.count
onTotalFileCountChanged: {
console.log("total files: " + totalFileCount);
// **** Refresh your view here ****
}
FolderListModel {
id: folderListModel
folder: "" // This gets updated by another function
nameFilters: [ "*.png" ]
}
如何刷新视图?!我看到许多属性的
FolderListModel
没有任何…已更改的
信号。怎么用?!看起来功能不完整。通过更改nameFilters:list
属性刷新模型时出现问题。因此,刷新会发生在任何其他属性更新上,如:folder=folder