FolderListModel QML Type
The FolderListModel provides a model of the contents of a file system folder. More...
Import Statement: | import Qt.labs.folderlistmodel 2.1 |
Properties
- count : int
- folder : string
- nameFilters : list<string>
- parentFolder : url
- rootFolder : url
- showDirs : bool
- showDirsFirst : bool
- showDotAndDotDot : bool
- showFiles : bool
- showHidden : bool
- showOnlyReadable : bool
- sortField : enumeration
- sortReversed : bool
Methods
Detailed Description
FolderListModel provides access to information about the contents of a folder in the local file system, exposing a list of files to views and other data components.
Note: This type is made available by importing the Qt.labs.folderlistmodel
module. Elements in the Qt.labs module are not guaranteed to remain compatible in future versions.
import Qt.labs.folderlistmodel 2.1
The folder property specifies the folder to access. Information about the files and directories in the folder is supplied via the model's interface. Components access names and paths via the following roles:
fileName
filePath
fileURL
(since Qt 5.2)fileBaseName
fileSuffix
fileSize
fileModified
fileAccessed
fileIsDir
Additionally a file entry can be differentiated from a folder entry via the isFolder() method.
Filtering
Various properties can be set to filter the number of files and directories exposed by the model.
The nameFilters property can be set to contain a list of wildcard filters that are applied to names of files and directories, causing only those that match the filters to be exposed.
Directories can be included or excluded using the showDirs property, navigation directories can also be excluded by setting the showDotAndDotDot property to false, hidden files can be included or excluded using the showHidden property.
It is sometimes useful to limit the files and directories exposed to those that the user can access. The showOnlyReadable property can be set to enable this feature.
Example Usage
The following example shows a FolderListModel being used to provide a list of QML files in a ListView:
import QtQuick 2.0 import Qt.labs.folderlistmodel 2.1 ListView { width: 200; height: 400 FolderListModel { id: folderModel nameFilters: ["*.qml"] } Component { id: fileDelegate Text { text: fileName } } model: folderModel delegate: fileDelegate }
Path Separators
Qt uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, Qt will translate your paths to conform to the underlying operating system.
See also QML Data Models.
Property Documentation
The folder property holds a URL for the folder that the model is currently providing.
The value must be a file
: or qrc
: URL, or a relative URL.
By default, the value is an invalid URL.
The nameFilters property contains a list of file name filters. The filters may include the ? and * wildcards.
The example below filters on PNG and JPEG files:
FolderListModel { nameFilters: [ "*.png", "*.jpg" ] }
Note: Directories are not excluded by filters.
rootFolder : url |
When the rootFolder is set, then this folder will be threated as the root in the file system, so that you can only travers sub folders from this rootFolder.
If true, directories are included in the model; otherwise only files are included.
By default, this property is true.
Note that the nameFilters are not applied to directories.
See also showDotAndDotDot.
If true, if directories are included in the model they will always be shown first, then the files.
By default, this property is false.
If true, the "." and ".." directories are included in the model; otherwise they are excluded.
By default, this property is false.
See also showDirs.
If true, files are included in the model; otherwise only directories are included.
By default, this property is true.
This QML property was introduced in Qt 5.2.
See also showDirs.
If true, hidden files and directories are included in the model; otherwise they are excluded.
By default, this property is false.
This QML property was introduced in Qt 5.2.
If true, only readable files and directories are shown; otherwise all files and directories are shown.
By default, this property is false.
See also showDirs.
The sortField property contains field to use for sorting. sortField may be one of:
- Unsorted - no sorting is applied.
- Name - sort by filename
- LastModified - sort by time modified
- Size - sort by file size
- Type - sort by file type (extension)
See also sortReversed.
If set to true, reverses the sort order. The default is false.
See also sortField.
Method Documentation
var get(int index, string property) |
Get the folder property for the given index. The following properties are available.
fileName
filePath
fileURL
(since Qt 5.2)fileBaseName
fileSuffix
fileSize
fileModified
fileAccessed
fileIsDir
© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.