QDir Class Reference
The QDir class provides access to directory structures and their contents.
- #include <QDir>
Note: All functions in this class are reentrant.
Detailed Description
The QDir class provides access to directory structures and their contents.
A QDir is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system. It can also be used to access Qt's resource system.
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.
A QDir can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.
Examples of absolute paths:
On Windows, the second example above will be translated to C:\Documents and Settings when used to access files.
Examples of relative paths:
You can use the isRelative() or isAbsolute() functions to check if a QDir is using a relative or an absolute file path. Call makeAbsolute() to convert a relative QDir to an absolute one.
Navigation and Directory Operations
A directory's path can be obtained with the path() function, and a new path set with the setPath() function. The absolute path to a directory is found by calling absolutePath().
The name of a directory is found using the dirName() function. This typically returns the last element in the absolute path that specifies the location of the directory. However, it can also return "." if the QDir represents the current directory.
The path for a directory can also be changed with the cd() and cdUp() functions, both of which operate like familiar shell commands. When cd() is called with the name of an existing directory, the QDir object changes directory so that it represents that directory instead. The cdUp() function changes the directory of the QDir object so that it refers to its parent directory; i.e. cd("..") is equivalent to cdUp().
Directories can be created with mkdir(), renamed with rename(), and removed with rmdir().
You can test for the presence of a directory with a given name by using exists(), and the properties of a directory can be tested with isReadable(), isAbsolute(), isRelative(), and isRoot().
The refresh() function re-reads the directory's data from disk.
Files and Directory Contents
Directories contain a number of entries, representing files, directories, and symbolic links. The number of entries in a directory is returned by count(). A string list of the names of all the entries in a directory can be obtained with entryList(). If you need information about each entry, use entryInfoList() to obtain a list of QFileInfo objects.
Paths to files and directories within a directory can be constructed using filePath() and absoluteFilePath(). The filePath() function returns a path to the specified file or directory relative to the path of the QDir object; absoluteFilePath() returns an absolute path to the specified file or directory. Neither of these functions checks for the existence of files or directory; they only construct paths.
Files can be removed by using the remove() function. Directories cannot be removed in the same way as files; use rmdir() to remove them instead.
It is possible to reduce the number of entries returned by entryList() and entryInfoList() by applying filters to a QDir object. You can apply a name filter to specify a pattern with wildcards that file names need to match, an attribute filter that selects properties of entries and can distinguish between files and directories, and a sort order.
Name filters are lists of strings that are passed to setNameFilters(). Attribute filters consist of a bitwise OR combination of Filters, and these are specified when calling setFilter(). The sort order is specified using setSorting() with a bitwise OR combination of SortFlags.
You can test to see if a filename matches a filter using the match() function.
Filter and sort order flags may also be specified when calling entryList() and entryInfoList() in order to override previously defined behavior.
The Current Directory and Other Special Paths
Access to some common directories is provided with a number of static functions that return QDir objects. There are also corresponding functions for these that return strings:
| QDir | QString | Return Value |
|---|---|---|
| current() | currentPath() | The application's working directory |
| home() | homePath() | The user's home directory |
| root() | rootPath() | The root directory |
| temp() | tempPath() | The system's temporary directory |
The setCurrent() static function can also be used to set the application's working directory.
If you want to find the directory containing the application's executable, see QCoreApplication::applicationDirPath().
The drives() static function provides a list of root directories for each device that contains a filing system. On Unix systems this returns a list containing a single root directory "/"; on Windows the list will usually contain C:/, and possibly other drive letters such as D:/, depending on the configuration of the user's system.
Path Manipulation and Strings
Paths containing "." elements that reference the current directory at that point in the path, ".." elements that reference the parent directory, and symbolic links can be reduced to a canonical form using the canonicalPath() function.
Paths can also be simplified by using cleanPath() to remove redundant "/" and ".." elements.
It is sometimes necessary to be able to show a path in the native representation for the user's platform. The static toNativeSeparators() function returns a copy of the specified path in which each directory separator is replaced by the appropriate separator for the underlying operating system.
Examples
Check if a directory exists:
- if (!dir.exists())
- qWarning("Cannot find the example directory");
(We could also use the static convenience function QFile::exists().)
Traversing directories and reading a file:
- if (!dir.cd("tmp")) { // "/tmp"
- qWarning("Cannot find the \"/tmp\" directory");
- } else {
- qWarning("Cannot create the file %s", file.name());
- }
A program that lists all the files in the current directory (excluding symbolic links), sorted by size, smallest first:
- #include <QDir>
- #include <iostream>
- int main(int argc, char *argv[])
- {
- QDir dir;
- std::cout << " Bytes Filename" << std::endl;
- for (int i = 0; i < list.size(); ++i) {
- .arg(fileInfo.fileName()));
- std::cout << std::endl;
- }
- return 0;
- }
See also QFileInfo, QFile, QFileDialog, QApplication::applicationDirPath(), and Find Files Example.
Public Types
| Toggle details | enum QDir:: | FilterFilter { Dirs , Files , Drives , NoSymLinks , AllEntries Dirs | Files | , TypeMask , All , Readable , Writable , Executable , PermissionMask , RWEMask , Modified , Hidden , System , AccessMask , AllDirs , CaseSensitive , NoDotAndDotDot , NoDot , NoDotDot , NoFilter , DefaultFilter NoFilter ...} { Dirs , Files , Drives , NoSymLinks , AllEntries Dirs | Files | , TypeMask , All , Readable , Writable , Executable , PermissionMask , RWEMask , Modified , Hidden , System , AccessMask , AllDirs , CaseSensitive , NoDotAndDotDot , NoDot , NoDotDot , NoFilter , DefaultFilter NoFilter } | |||||||||||||||||||||||||||||||||||||||||||||||||||
This enum describes the filtering options available to QDir; e.g. for entryList() and entryInfoList(). The filter value is specified by combining values from the following list using the bitwise OR operator:
Functions that use Filter enum values to filter lists of files and directories will include symbolic links to files and directories unless you set the NoSymLinks value. A default constructed QDir will not filter out files based on their permissions, so entryList() and entryInfoList() will return all files that are readable, writable, executable, or any combination of the three. This makes the default easy to write, and at the same time useful. For example, setting the Readable, Writable, and Files flags allows all files to be listed for which the application has read access, write access or both. If the Dirs and Drives flags are also included in this combination then all drives, directories, all files that the application can read, write, or execute, and symlinks to such files/directories can be listed. To retrieve the permissons for a directory, use the entryInfoList() function to get the associated QFileInfo objects and then use the QFileInfo::permissons() to obtain the permissions and ownership for each file. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Look up this member in the source code. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Toggle details | enum QDir:: | SortFlagSortFlag { Name , Time , Size , Unsorted , SortByMask , DirsFirst , Reversed , IgnoreCase , DirsLast , LocaleAware , Type , NoSort , DefaultSort NoSort ...} { Name , Time , Size , Unsorted , SortByMask , DirsFirst , Reversed , IgnoreCase , DirsLast , LocaleAware , Type , NoSort , DefaultSort NoSort } | |||||||||||||||||||||||||||||||||||||||||||||||||||
This enum describes the sort options available to QDir, e.g. for entryList() and entryInfoList(). The sort value is specified by OR-ing together values from the following list:
You can only specify one of the first four. If you specify both DirsFirst and Reversed, directories are still put first, but in reverse order; the files will be listed after the directories, again in reverse order. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Look up this member in the source code. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
Types
| Toggle details | typedef QDir | FilterSpecFilterSpec |
Use QDir::Filters instead. | ||
Look up this member in the source code. | ||
| Toggle details | typedef QDir | SortSpecSortSpec |
Use QDir::SortFlags instead. | ||
Look up this member in the source code. | ||
Public Functions
| Toggle details | QDir | QDirQDir ( const QDir &dir ) ( const QDir &dir ) |
Look up this member in the source code. | ||
| Toggle details | QDir | QDirQDir ( const QString &path=QString() ) ( const QString &path=QString() ) |
Constructs a QDir pointing to the given directory path. If path is empty the program's working directory, ("."), is used. See also currentPath(). | ||
Look up this member in the source code. | ||
| Toggle details | QDir | QDirQDir ( const QString &path , const QString &nameFilter , SortFlags sort=SortFlags( Name | IgnoreCase ) , Filters filters=AllEntries ...) ( const QString &path , const QString &nameFilter , SortFlags sort=SortFlags( Name | IgnoreCase ) , Filters filters=AllEntries ) |
Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters. It also sorts the names using sort. The default nameFilter is an empty string, which excludes nothing; the default filters is AllEntries, which also means exclude nothing. The default sort is Name | IgnoreCase, i.e. sort by name case-insensitively. If path is an empty string, QDir uses "." (the current directory). If nameFilter is an empty string, QDir uses the name filter "*" (all files). Note that path need not exist. See also exists(), setPath(), setNameFilter(), setFilter(), and setSorting(). | ||
Look up this member in the source code. | ||
| Toggle details | QDir | ~QDir~QDir () () |
Destroys the QDir object frees up its resources. This has no effect on the underlying directory in the file system. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | absoluteFilePathabsoluteFilePath ( const QString &fileName ) ( const QString &fileName )const |
Returns the absolute path name of a file in the directory. Does not check if the file actually exists in the directory; but see exists(). Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()). See also relativeFilePath(), filePath(), and canonicalPath(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | absolutePathabsolutePath () ()const |
Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators. See also setPath(), canonicalPath(), exists(), cleanPath(), dirName(), and absoluteFilePath(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | addSearchPathaddSearchPath ( const QString &prefix , const QString &path ...) ( const QString &prefix , const QString &path ) [static] |
Adds path to the search path for prefix. See also setSearchPaths(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | canonicalPathcanonicalPath () ()const |
Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements. On systems that do not have symbolic links this function will always return the same string that absolutePath() returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath() returns an empty string. Example:
See also path(), absolutePath(), exists(), cleanPath(), dirName(), and absoluteFilePath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | |
Changes the QDir's directory to dirName. Returns true if the new directory exists and is readable; otherwise returns false. Note that the logical cd() operation is not performed if the new directory does not exist. Calling cd("..") is equivalent to calling cdUp(). See also cdUp(), isReadable(), exists(), and path(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | cdUpcdUp () () |
Changes directory by moving one directory up from the QDir's current directory. Returns true if the new directory exists and is readable; otherwise returns false. Note that the logical cdUp() operation is not performed if the new directory does not exist. See also cd(), isReadable(), exists(), and path(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | cleanPathcleanPath ( const QString &path ) ( const QString &path ) [static] |
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path, path. Symbolic links are kept. This function does not return the canonical path, but rather the simplest version of the input. For example, "./local" becomes "local", "local/../bin" becomes "bin" and "/local/usr/../bin" becomes "/local/bin". See also absolutePath() and canonicalPath(). | ||
Look up this member in the source code. | ||
| Toggle details | uint QDir | countcount () ()const |
Returns the total number of directories and files in the directory. Equivalent to entryList().count(). See also operator[]() and entryList(). | ||
Look up this member in the source code. | ||
| Toggle details | QDir QDir | currentcurrent () () [static] |
Returns the application's current directory. The directory is constructed using the absolute path of the current directory, ensuring that its path() will be the same as its absolutePath(). See also currentPath(), setCurrent(), home(), root(), and temp(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | currentPathcurrentPath () () [static] |
Returns the absolute path of the application's current directory. See also current(), setCurrent(), homePath(), rootPath(), and tempPath(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | dirNamedirName () ()const |
Returns the name of the directory; this is not the same as the path, e.g. a directory with the name "mail", might have the path "/var/spool/mail". If the directory has no name (e.g. it is the root directory) an empty string is returned. No check is made to ensure that a directory with this name actually exists; but see exists(). See also path(), filePath(), absolutePath(), and absoluteFilePath(). | ||
Look up this member in the source code. | ||
| Toggle details | QFileInfoList QDir | drivesdrives () () [static] |
Look up this member in the source code. | ||
| Toggle details | QFileInfoList QDir | entryInfoListentryInfoList ( const QStringList &nameFilters , Filters filters=NoFilter , SortFlags sort=NoSort ...) ( const QStringList &nameFilters , Filters filters=NoFilter , SortFlags sort=NoSort )const |
Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. See also entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), and exists(). | ||
Look up this member in the source code. | ||
| Toggle details | QFileInfoList QDir | entryInfoListentryInfoList ( Filters filters=NoFilter , SortFlags sort=NoSort ...) ( Filters filters=NoFilter , SortFlags sort=NoSort )const |
This is an overloaded function. Returns a list of QFileInfo objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). The attribute filter and sorting specifications can be overridden using the filters and sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. See also entryList(), setNameFilters(), setSorting(), setFilter(), isReadable(), and exists(). | ||
Look up this member in the source code. | ||
| Toggle details | QStringList QDir | entryListentryList ( const QStringList &nameFilters , Filters filters=NoFilter , SortFlags sort=NoSort ...) ( const QStringList &nameFilters , Filters filters=NoFilter , SortFlags sort=NoSort )const |
Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. See also entryInfoList(), setNameFilters(), setSorting(), and setFilter(). | ||
Look up this member in the source code. | ||
| Toggle details | QStringList QDir | entryListentryList ( Filters filters=NoFilter , SortFlags sort=NoSort ...) ( Filters filters=NoFilter , SortFlags sort=NoSort )const |
This is an overloaded function. Returns a list of the names of all the files and directories in the directory, ordered according to the name and attribute filters previously set with setNameFilters() and setFilter(), and sorted according to the flags set with setSorting(). The attribute filter and sorting specifications can be overridden using the filters and sort arguments. Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification. Note: To list symlinks that point to non existing files, System must be passed to the filter. See also entryInfoList(), setNameFilters(), setSorting(), and setFilter(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | existsexists ( const QString &name ) ( const QString &name )const |
Returns true if the file called name exists; otherwise returns false. Unless name contains an absolute file path, the file name is assumed to be relative to the directory itself, so this function is typically used to check for the presence of files within a directory. See also QFileInfo::exists() and QFile::exists(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | existsexists () ()const |
This is an overloaded function. Returns true if the directory exists; otherwise returns false. (If a file with the same name is found this function will return false). The overload of this function that accepts an argument is used to test for the presence of files and directories within a directory. See also QFileInfo::exists() and QFile::exists(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | filePathfilePath ( const QString &fileName ) ( const QString &fileName )const |
Returns the path name of a file in the directory. Does not check if the file actually exists in the directory; but see exists(). If the QDir is relative the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()). See also dirName(), absoluteFilePath(), isRelative(), and canonicalPath(). | ||
Look up this member in the source code. | ||
| Toggle details | Filters QDir | filterfilter () ()const |
Look up this member in the source code. | ||
| Toggle details | QString QDir | fromNativeSeparatorsfromNativeSeparators ( const QString &pathName ...) ( const QString &pathName ) [static] |
Returns pathName using '/' as file separator. On Windows, for instance, fromNativeSeparators("c:\\winnt\\system32") returns "c:/winnt/system32". The returned string may be the same as the argument on some operating systems, for example on Unix. See also toNativeSeparators() and separator(). | ||
Look up this member in the source code. | ||
| Toggle details | QDir QDir | homehome () () [static] |
Look up this member in the source code. | ||
| Toggle details | QString QDir | homePathhomePath () () [static] |
Returns the absolute path of the user's home directory. Under Windows this function will return the directory of the current user's profile. Typically, this is:
Use the toNativeSeparators() function to convert the separators to the ones that are appropriate for the underlying operating system. If the directory of the current user's profile does not exist or cannot be retrieved, the following alternatives will be checked (in the given order) until an existing and available path is found:
Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath(). On Symbian always the same as the path returned by the rootPath(). See also home(), currentPath(), rootPath(), and tempPath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | isAbsoluteisAbsolute () ()const |
Returns true if the directory's path is absolute; otherwise returns false. See isAbsolutePath(). See also isRelative(), makeAbsolute(), and cleanPath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | isAbsolutePathisAbsolutePath ( const QString &path ) ( const QString &path ) [static] |
Returns true if path is absolute; returns false if it is relative. See also isAbsolute(), isRelativePath(), makeAbsolute(), and cleanPath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | isReadableisReadable () ()const |
Returns true if the directory is readable and we can open files by name; otherwise returns false. Warning: A false value from this function is not a guarantee that files in the directory are not accessible. See also QFileInfo::isReadable(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | isRelativeisRelative () ()const |
Returns true if the directory path is relative; otherwise returns false. (Under Unix a path is relative if it does not start with a "/"). See also makeAbsolute(), isAbsolute(), isAbsolutePath(), and cleanPath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | isRelativePathisRelativePath ( const QString &path ) ( const QString &path ) [static] |
Returns true if path is relative; returns false if it is absolute. See also isRelative(), isAbsolutePath(), and makeAbsolute(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | isRootisRoot () ()const |
Returns true if the directory is the root directory; otherwise returns false. Note: If the directory is a symbolic link to the root directory this function returns false. If you want to test for this use canonicalPath(), e.g.
| ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | makeAbsolutemakeAbsolute () () |
Converts the directory path to an absolute path. If it is already absolute nothing happens. Returns true if the conversion succeeded; otherwise returns false. See also isAbsolute(), isAbsolutePath(), isRelative(), and cleanPath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | matchmatch ( const QString &filter , const QString &fileName ...) ( const QString &filter , const QString &fileName ) [static] |
Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false. The filter may contain multiple patterns separated by spaces or semicolons. The matching is case insensitive. See also QRegExp wildcard matching, QRegExp::exactMatch(), entryList(), and entryInfoList(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | matchmatch ( const QStringList &filters , const QString &fileName ...) ( const QStringList &filters , const QString &fileName ) [static] |
This is an overloaded function. Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false. The matching is case insensitive. See also QRegExp wildcard matching, QRegExp::exactMatch(), entryList(), and entryInfoList(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | mkdirmkdir ( const QString &dirName ) ( const QString &dirName )const |
Creates a sub-directory called dirName. Returns true on success; otherwise returns false. See also rmdir(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | mkpathmkpath ( const QString &dirPath ) ( const QString &dirPath )const |
Creates the directory path dirPath. The function will create all parent directories necessary to create the directory. Returns true if successful; otherwise returns false. See also rmpath(). | ||
Look up this member in the source code. | ||
| Toggle details | QStringList QDir | nameFiltersnameFilters () ()const |
Returns the string list set by setNameFilters() See also setNameFilters(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | pathpath () ()const |
Returns the path. This may contain symbolic links, but never contains redundant ".", ".." or multiple separators. The returned path can be either absolute or relative (see setPath()). See also setPath(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath(), toNativeSeparators(), and makeAbsolute(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | refreshrefresh () ()const |
Refreshes the directory information. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | relativeFilePathrelativeFilePath ( const QString &fileName ) ( const QString &fileName )const |
Returns the path to fileName relative to the directory.
See also absoluteFilePath(), filePath(), and canonicalPath(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | removeremove ( const QString &fileName ) ( const QString &fileName ) |
Removes the file, fileName. Returns true if the file is removed successfully; otherwise returns false. | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | renamerename ( const QString &oldName , const QString &newName ...) ( const QString &oldName , const QString &newName ) |
Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false. On most file systems, rename() fails only if oldName does not exist, if newName and oldName are not on the same partition or if a file with the new name already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if newName points to an open file. | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | rmdirrmdir ( const QString &dirName ) ( const QString &dirName )const |
Removes the directory specified by dirName. The directory must be empty for rmdir() to succeed. Returns true if successful; otherwise returns false. See also mkdir(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | rmpathrmpath ( const QString &dirPath ) ( const QString &dirPath )const |
Removes the directory path dirPath. The function will remove all parent directories in dirPath, provided that they are empty. This is the opposite of mkpath(dirPath). Returns true if successful; otherwise returns false. See also mkpath(). | ||
Look up this member in the source code. | ||
| Toggle details | QDir QDir | rootroot () () [static] |
Look up this member in the source code. | ||
| Toggle details | QString QDir | rootPathrootPath () () [static] |
Returns the absolute path of the root directory. For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/". On Symbian this typically returns "c:/data", i.e. the same as native PathInfo::PhoneMemoryRootPath(). See also root(), drives(), currentPath(), homePath(), and tempPath(). | ||
Look up this member in the source code. | ||
| Toggle details | QStringList QDir | searchPathssearchPaths ( const QString &prefix ) ( const QString &prefix ) [static] |
Returns the search paths for prefix. See also setSearchPaths() and addSearchPath(). | ||
Look up this member in the source code. | ||
| Toggle details | QChar QDir | separatorseparator () () [static] |
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\" under Windows. You do not need to use this function to build file paths. If you always use "/", Qt will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | setCurrentsetCurrent ( const QString &path ) ( const QString &path ) [static] |
Sets the application's current working directory to path. Returns true if the directory was successfully changed; otherwise returns false. See also current(), currentPath(), home(), root(), and temp(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | setFiltersetFilter ( Filters filters ) ( Filters filters ) |
Sets the filter used by entryList() and entryInfoList() to filters. The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList(). See QDir::Filter. See also filter() and setNameFilters(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | setNameFilterssetNameFilters ( const QStringList &nameFilters ...) ( const QStringList &nameFilters ) |
Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nameFilters. Each name filter is a wildcard (globbing) filter that understands * and ? wildcards. (See QRegExp wildcard matching.) For example, the following code sets three name filters on a QDir to ensure that only files with extensions typically used for C++ source files are listed:
See also nameFilters() and setFilter(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | setPathsetPath ( const QString &path ) ( const QString &path ) |
Sets the path of the directory to path. The path is cleaned of redundant ".", ".." and of multiple separators. No check is made to see whether a directory with this path actually exists; but you can check for yourself using exists(). The path can be either absolute or relative. Absolute paths begin with the directory separator "/" (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory. An example of an absolute path is the string "/tmp/quartz", a relative path might look like "src/fatlib". See also path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath(), isRelative(), and makeAbsolute(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | setSearchPathssetSearchPaths ( const QString &prefix , const QStringList &searchPaths ...) ( const QString &prefix , const QStringList &searchPaths ) [static] |
Sets or replaces Qt's search paths for file names with the prefix prefix to searchPaths. To specify a prefix for a file name, prepend the prefix followed by a single colon (e.g., "images:undo.png", "xmldocs:books.xml"). prefix can only contain letters or numbers (e.g., it cannot contain a colon, nor a slash). Qt uses this search path to locate files with a known prefix. The search path entries are tested in order, starting with the first entry.
File name prefix must be at least 2 characters long to avoid conflicts with Windows drive letters. Search paths may contain paths to The Qt Resource System. See also searchPaths(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | setSortingsetSorting ( SortFlags sort ) ( SortFlags sort ) |
Sets the sort order used by entryList() and entryInfoList(). The sort is specified by OR-ing values from the enum QDir::SortFlag. | ||
Look up this member in the source code. | ||
| Toggle details | SortFlags QDir | sortingsorting () ()const |
Returns the value set by setSorting() See also setSorting() and SortFlag. | ||
Look up this member in the source code. | ||
| Toggle details | QDir QDir | temptemp () () [static] |
Look up this member in the source code. | ||
| Toggle details | QString QDir | tempPathtempPath () () [static] |
Returns the absolute path of the system's temporary directory. On Unix/Linux systems this is usually /tmp; on Windows this is usually the path in the TEMP or TMP environment variable. Whether a directory separator is added to the end or not, depends on the operating system. See also temp(), currentPath(), homePath(), and rootPath(). | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | toNativeSeparatorstoNativeSeparators ( const QString &pathName ...) ( const QString &pathName ) [static] |
Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32". The returned string may be the same as the argument on some operating systems, for example on Unix. See also fromNativeSeparators() and separator(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | operator!=operator!= ( const QDir &dir ) ( const QDir &dir )const |
Look up this member in the source code. | ||
| Toggle details | QDir & QDir | operator=operator= ( const QDir &dir ) ( const QDir &dir ) |
Makes a copy of the dir object and assigns it to this QDir object. | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | operator==operator== ( const QDir &dir ) ( const QDir &dir )const |
Look up this member in the source code. | ||
| Toggle details | QString QDir | operator[]operator[] ( int pos ) ( int pos )const |
Look up this member in the source code. | ||
| Toggle details | void QDir | addResourceSearchPathaddResourceSearchPath ( const QString &path ) ( const QString &path ) [static] |
Use QDir::addSearchPath() with a prefix instead. Adds path to the search paths searched in to find resources that are not specified with an absolute path. The default search path is to search only in the root (:/). See also The Qt Resource System. | ||
Look up this member in the source code. | ||
| Toggle details | QDir & QDir | operator=operator= ( const QString &path ) ( const QString &path ) |
Look up this member in the source code. | ||
| Toggle details | QString QDir | absFilePathabsFilePath ( const QString &fileName ,
bool
acceptAbsPath=true ...) ( const QString &fileName ,
bool
acceptAbsPath=true )const |
Use absoluteFilePath(fileName) instead. The acceptAbsPath parameter is ignored. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | absPathabsPath () ()const |
Use absolutePath() instead. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | cleanDirPathcleanDirPath ( const QString &name ) ( const QString &name ) [static] |
Use cleanPath() instead. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | convertSeparatorsconvertSeparators ( const QString &pathName ( const QString &pathName ) [static] |
Use QDir::toNativeSeparators() instead. | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | convertToAbsconvertToAbs () () |
Use makeAbsolute() instead. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | currentDirPathcurrentDirPath () () [static] |
Returns the absolute path of the application's current directory. Use currentPath() instead. See also currentPath() and setCurrent(). | ||
Look up this member in the source code. | ||
| Toggle details | QFileInfoList QDir | entryInfoListentryInfoList ( const QString &nameFilter ,
Filters
filters=NoFilter ,
SortFlags
sort=NoSort ...) ( const QString &nameFilter ,
Filters
filters=NoFilter ,
SortFlags
sort=NoSort )const |
This is an overloaded function. Use the overload that takes a name filter string list as first argument instead of a combination of attribute filter flags. | ||
Look up this member in the source code. | ||
| Toggle details | QStringList QDir | entryListentryList ( const QString &nameFilter ,
Filters
filters=NoFilter ,
SortFlags
sort=NoSort ...) ( const QString &nameFilter ,
Filters
filters=NoFilter ,
SortFlags
sort=NoSort )const |
This is an overloaded function. Use the overload that takes a name filter string list as first argument instead of a combination of attribute filter flags. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | homeDirPathhomeDirPath () () [static] |
Look up this member in the source code. | ||
| Toggle details | bool QDir | matchAllDirsmatchAllDirs () ()const |
Use filter() & AllDirs instead. See also setMatchAllDirs(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | mkdirmkdir ( const QString &dirName ,
bool
acceptAbsPath ...) ( const QString &dirName ,
bool
acceptAbsPath )const |
Use mkdir(dirName) instead. The acceptAbsPath parameter is ignored. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | nameFilternameFilter () ()const |
Use nameFilters() instead. See also setNameFilter(). | ||
Look up this member in the source code. | ||
| Toggle details | bool QDir | rmdirrmdir ( const QString &dirName ,
bool
acceptAbsPath ...) ( const QString &dirName ,
bool
acceptAbsPath )const |
Use rmdir(dirName) instead. The acceptAbsPath parameter is ignored. | ||
Look up this member in the source code. | ||
| Toggle details | QString QDir | rootDirPathrootDirPath () () [static] |
Look up this member in the source code. | ||
| Toggle details | void QDir | setMatchAllDirssetMatchAllDirs (
bool
on ) (
bool
on ) |
Use setFilter() instead. See also matchAllDirs(). | ||
Look up this member in the source code. | ||
| Toggle details | void QDir | setNameFiltersetNameFilter ( const QString &nameFilter ) ( const QString &nameFilter ) |
Use setNameFilters() instead. The nameFilter is a wildcard (globbing) filter that understands "*" and "?" wildcards. (See QRegExp wildcard matching.) You may specify several filter entries, each separated by spaces or by semicolons. For example, if you want entryList() and entryInfoList() to list all files ending with either ".cpp" or ".h", you would use either dir.setNameFilters("*.cpp *.h") or dir.setNameFilters("*.cpp;*.h"). For example, if you have code like
you can rewrite it as
See also nameFilter(). | ||
Look up this member in the source code. | ||
Macros
| Toggle details | Q_CLEANUP_RESOURCEQ_CLEANUP_RESOURCE ( name ) |
Unloads the resources specified by the .qrc file with the base name name. Normally, Qt resources are unloaded automatically when the application terminates, but if the resources are located in a plugin that is being unloaded, call Q_CLEANUP_RESOURCE() to force removal of your resources. Note: This macro cannot be used in a namespace. Please see the Q_INIT_RESOURCE documentation for a workaround. Example:
See also Q_INIT_RESOURCE() and The Qt Resource System. | |
| Toggle details | Q_INIT_RESOURCEQ_INIT_RESOURCE ( name ) |
Initializes the resources specified by the .qrc file with the specified base name. Normally, Qt resources are loaded automatically at startup. The Q_INIT_RESOURCE() macro is necessary on some platforms for resources stored in a static library. For example, if your application's resources are listed in a file called myapp.qrc, you can ensure that the resources are initialized at startup by adding this line to your main() function:
If the file name contains characters that cannot be part of a valid C++ function name (such as '-'), they have to be replaced by the underscore character ('_'). Note: This macro cannot be used in a namespace. It should be called from main(). If that is not possible, the following workaround can be used to init the resource myapp from the function MyNamespace::myFunction:
See also Q_CLEANUP_RESOURCE() and The Qt Resource System. | |



Votes: 1
Coverage: Qt library 4.7, 4.8, 5.0
Robot Herder
35 notes
Q_INIT_RESOURCE: names must be unique
If you have multiple resources, say from multiple (static) libs, you must make sure that the names of the resource files (filename of the .qrc/.rcc) are unique. Otherwise only one one of the equal named resources is available in your application, but not the others.
[Revisions]