qml 文件夹列表模型 [英] qml FolderListModel

查看:31
本文介绍了qml 文件夹列表模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 FolderListModel,根据这个 example

I am trying to use FolderListModel, according to this example

像这样:

 ListView
{
    anchors.fill: parent
    FolderListModel
    {
        id: foldermodel
        folder: "C:/Qt/Projects/"
        showDirs: true
        showDotAndDotDot: true
        nameFilters: ["*"]
        sortField :  "Name"
    }
    Component {
        id: filedelegate
        Text { text: fileName }
    }
    model: foldermodel
    delegate: filedelegate
}

我想以递归方式显示基本目录下的所有文件/目录.有人知道怎么做吗?

i want to show all the files/directories under the base directory, in a recursive way. does any one have an idea how to do that?

推荐答案

您的 folder 属性中的 URL 似乎无效.FolderListModel 文档 元素将文件夹"属性描述为:

It seems that you have an invalid URL in the folder property. Documentation for FolderListModel element describes 'folder' property as:

文件夹属性包含模型当前提供的文件夹的 URL.该值是表示为字符串的 URL,并且必须是 file: 或 qrc: URL 或相对 URL.默认情况下,该值为无效的 URL.

The folder property holds a URL for the folder that the model is currently providing. The value is a URL expressed as a string, and must be a file: or qrc: URL, or a relative URL. By default, the value is an invalid URL.

这意味着文件夹属性的格式必须为 folder: "file:///[Directory path]".例如,尝试在这种情况下将您的文件夹属性更改为:folder: "file:///C:/Qt/Projects/" 看看是否可行.

This means that the folder property must be in format folder: "file:///[Directory path]". For instance, try changing your folder property in this case to: folder: "file:///C:/Qt/Projects/" and see if that works.

这篇关于qml 文件夹列表模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆