QDirModel Class
The QDirModel class provides a data model for the local filesystem. More...
| Header: | #include <QDirModel> |
| qmake: | QT += widgets |
| Inherits: | QAbstractItemModel |
This class is obsolete. It is provided to keep old source code working. We strongly advise against using it in new code.
Public Types
| enum | Roles { FileIconRole, FilePathRole, FileNameRole } |
Properties
- lazyChildCount : bool
- readOnly : bool
- resolveSymlinks : bool
Public Functions
| bool | isReadOnly() const |
| bool | lazyChildCount() const |
| bool | resolveSymlinks() const |
| void | setLazyChildCount(bool enable) |
| void | setReadOnly(bool enable) |
| void | setResolveSymlinks(bool enable) |
Detailed Description
The usage of QDirModel is not recommended anymore. The QFileSystemModel class is a more performant alternative.
This class provides access to the local filesystem, providing functions for renaming and removing files and directories, and for creating new directories. In the simplest case, it can be used with a suitable display widget as part of a browser or filer.
QDirModel keeps a cache with file information. The cache needs to be updated with refresh().
QDirModel can be accessed using the standard interface provided by QAbstractItemModel, but it also provides some convenience functions that are specific to a directory model. The fileInfo() and isDir() functions provide information about the underlying files and directories related to items in the model.
Directories can be created and removed using mkdir(), rmdir(), and the model will be automatically updated to take the changes into account.
Note: QDirModel requires an instance of QApplication.
See also nameFilters(), setFilter(), filter(), QListView, QTreeView, QFileSystemModel, Dir View Example, and Model Classes.
Member Type Documentation
enum QDirModel::Roles
| Constant | Value |
|---|---|
QDirModel::FileIconRole | Qt::DecorationRole |
QDirModel::FilePathRole | Qt::UserRole + 1 |
QDirModel::FileNameRole | 258 |
Property Documentation
lazyChildCount : bool
This property holds whether the directory model optimizes the hasChildren function to only check if the item is a directory.
If this property is set to false, the directory model will make sure that a directory actually containes any files before reporting that it has children. Otherwise the directory model will report that an item has children if the item is a directory.
This property is false by default
Access functions:
| bool | lazyChildCount() const |
| void | setLazyChildCount(bool enable) |
readOnly : bool
This property holds whether the directory model allows writing to the file system
If this property is set to false, the directory model will allow renaming, copying and deleting of files and directories.
This property is true by default
Access functions:
| bool | isReadOnly() const |
| void | setReadOnly(bool enable) |
resolveSymlinks : bool
This property holds whether the directory model should resolve symbolic links
This is only relevant on operating systems that support symbolic links.
Access functions:
| bool | resolveSymlinks() const |
| void | setResolveSymlinks(bool enable) |