Home · Overviews · Examples 

QDirModel Class Reference
[com.trolltech.qt.gui module]

The QDirModel class provides a data model for the local filesystem. More...

Inherits QAbstractItemModel.


Detailed Description

The QDirModel class provides a data model for the local filesystem.

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.

A directory model that displays the contents of a default directory is usually constructed with a parent object:

        QDirModel *model = new QDirModel;

A tree view can be used to display the contents of the model

        QTreeView *tree = new QTreeView(splitter);
        tree->setModel(model);

and the contents of a particular directory can be displayed by setting the tree view's root index:

        tree->setRootIndex(model->index(QDir::currentPath()));

The view's root index can be used to control how much of a hierarchical model is displayed. QDirModel provides a convenience function that returns a suitable model index for a path to a directory within the model.

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, isDir, name(), and path() 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.

See also nameFilters, setFilter, filter, QListView, QTreeView, Dir View Example, and Model Classes.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.4_01