qml FolderListModel

2019-04-07 00:27发布

I am trying to use FolderListModel, according to this example

like this:

 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?

2条回答
老娘就宠你
2楼-- · 2019-04-07 01:13

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

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.

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-04-07 01:13

I think this cant be done without crawling the fs , this would requiere to create a list model and copy the tree inside ...

btw beware of cycles , filter . and .. out

-- http://rzr.online.fr/q/qml

查看更多
登录 后发表回答