Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Variables | List of all members
QDir Class Reference

The QDir class provides access to directory structures and their contents. More...

#include <qdir.h>

Public Types

enum  Filter {
  Dirs = 0x001, Files = 0x002, Drives = 0x004, NoSymLinks = 0x008,
  AllEntries = Dirs | Files | Drives, TypeMask = 0x00f, Readable = 0x010, Writable = 0x020,
  Executable = 0x040, PermissionMask = 0x070, Modified = 0x080, Hidden = 0x100,
  System = 0x200, AccessMask = 0x3F0, AllDirs = 0x400, CaseSensitive = 0x800,
  NoDotAndDotDot = 0x1000, NoDot = 0x2000, NoDotDot = 0x4000, NoFilter = -1
}
 This enum describes the filtering options available to QDir; e. More...
 
enum  SortFlag {
  Name = 0x00, Time = 0x01, Size = 0x02, Unsorted = 0x03,
  SortByMask = 0x03, DirsFirst = 0x04, Reversed = 0x08, IgnoreCase = 0x10,
  DirsLast = 0x20, LocaleAware = 0x40, Type = 0x80, NoSort = -1
}
 This enum describes the sort options available to QDir, e. More...
 

Public Functions

QString absoluteFilePath (const QString &fileName) const
 Returns the absolute path name of a file in the directory. More...
 
QString absolutePath () 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. More...
 
QString canonicalPath () const
 Returns the canonical path, i.e. More...
 
bool cd (const QString &dirName)
 Changes the QDir's directory to dirName. More...
 
bool cdUp ()
 Changes directory by moving one directory up from the QDir's current directory. More...
 
uint count () const
 Returns the total number of directories and files in the directory. More...
 
QString dirName () const
 Returns the name of the directory; this is not the same as the path, e.g. More...
 
QFileInfoList entryInfoList (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(). More...
 
QFileInfoList entryInfoList (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(). More...
 
QStringList entryList (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(). More...
 
QStringList entryList (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(). More...
 
bool exists () const
 Returns true if the directory exists; otherwise returns false. More...
 
bool exists (const QString &name) const
 Returns true if the file called name exists; otherwise returns false. More...
 
QString filePath (const QString &fileName) const
 Returns the path name of a file in the directory. More...
 
Filters filter () const
 Returns the value set by setFilter() More...
 
bool isAbsolute () const
 Returns true if the directory's path is absolute; otherwise returns false. More...
 
bool isReadable () const
 Returns true if the directory is readable and we can open files by name; otherwise returns false. More...
 
bool isRelative () const
 Returns true if the directory path is relative; otherwise returns false. More...
 
bool isRoot () const
 Returns true if the directory is the root directory; otherwise returns false. More...
 
bool makeAbsolute ()
 Converts the directory path to an absolute path. More...
 
bool mkdir (const QString &dirName) const
 Creates a sub-directory called dirName. More...
 
bool mkpath (const QString &dirPath) const
 Creates the directory path dirPath. More...
 
QStringList nameFilters () const
 Returns the string list set by setNameFilters() More...
 
bool operator!= (const QDir &dir) const
 Returns true if directory dir and this directory have different paths or different sort or filter settings; otherwise returns false. More...
 
QDiroperator= (const QDir &)
 Makes a copy of the dir object and assigns it to this QDir object. More...
 
QDiroperator= (const QString &path)
 Sets the directory path to the given path. More...
 
bool operator== (const QDir &dir) const
 Returns true if directory dir and this directory have the same path and their sort and filter settings are the same; otherwise returns false. More...
 
QString operator[] (int) const
 Returns the file name at position pos in the list of file names. More...
 
QString path () const
 Returns the path. More...
 
 QDir (const QDir &)
 Constructs a QDir object that is a copy of the QDir object for directory dir. More...
 
 QDir (const QString &path=QString())
 Constructs a QDir pointing to the given directory path. More...
 
 QDir (const QString &path, const QString &nameFilter, SortFlags sort=SortFlags(Name|IgnoreCase), Filters filter=AllEntries)
 Constructs a QDir with path path, that filters its entries by name using nameFilter and by attributes using filters. More...
 
void refresh () const
 Refreshes the directory information. More...
 
QString relativeFilePath (const QString &fileName) const
 Returns the path to fileName relative to the directory. More...
 
bool remove (const QString &fileName)
 Removes the file, fileName. More...
 
bool rename (const QString &oldName, const QString &newName)
 Renames a file or directory from oldName to newName, and returns true if successful; otherwise returns false. More...
 
bool rmdir (const QString &dirName) const
 Removes the directory specified by dirName. More...
 
bool rmpath (const QString &dirPath) const
 Removes the directory path dirPath. More...
 
void setFilter (Filters filter)
 Sets the filter used by entryList() and entryInfoList() to filters. More...
 
void setNameFilters (const QStringList &nameFilters)
 Sets the name filters used by entryList() and entryInfoList() to the list of filters specified by nameFilters. More...
 
void setPath (const QString &path)
 Sets the path of the directory to path. More...
 
void setSorting (SortFlags sort)
 Sets the sort order used by entryList() and entryInfoList(). More...
 
SortFlags sorting () const
 Returns the value set by setSorting() More...
 
 ~QDir ()
 Destroys the QDir object frees up its resources. More...
 

Static Public Functions

static void addResourceSearchPath (const QString &path)
 Use QDir::addSearchPath() with a prefix instead. More...
 
static void addSearchPath (const QString &prefix, const QString &path)
 
static QString cleanPath (const QString &path)
 Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path, path. More...
 
static QT_DEPRECATED QString convertSeparators (const QString &pathName)
 Use QDir::toNativeSeparators() instead. More...
 
static QDir current ()
 Returns the application's current directory. More...
 
static QString currentPath ()
 Returns the absolute path of the application's current directory. More...
 
static QFileInfoList drives ()
 Returns a list of the root directories on this system. More...
 
static QString fromNativeSeparators (const QString &pathName)
 Returns pathName using '/' as file separator. More...
 
static QDir home ()
 Returns the user's home directory. More...
 
static QString homePath ()
 Returns the absolute path of the user's home directory. More...
 
static bool isAbsolutePath (const QString &path)
 Returns true if path is absolute; returns false if it is relative. More...
 
static bool isRelativePath (const QString &path)
 Returns true if path is relative; returns false if it is absolute. More...
 
static bool match (const QStringList &filters, const QString &fileName)
 Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false. More...
 
static bool match (const QString &filter, const QString &fileName)
 Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false. More...
 
static QStringList nameFiltersFromString (const QString &nameFilter)
 Returns a list of name filters from the given nameFilter. More...
 
static QDir root ()
 Returns the root directory. More...
 
static QString rootPath ()
 Returns the absolute path of the root directory. More...
 
static QStringList searchPaths (const QString &prefix)
 
static QChar separator ()
 Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows. More...
 
static bool setCurrent (const QString &path)
 Sets the application's current working directory to path. More...
 
static void setSearchPaths (const QString &prefix, const QStringList &searchPaths)
 
static QDir temp ()
 Returns the system's temporary directory. More...
 
static QString tempPath ()
 Returns the absolute path of the system's temporary directory. More...
 
static QString toNativeSeparators (const QString &pathName)
 Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system. More...
 

Protected Variables

QSharedDataPointer< QDirPrivated_ptr
 

Detailed Description

The QDir class provides access to directory structures and their contents.

Note
This class or function is reentrant.

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:

QDir("/home/user/Documents")
QDir("C:/Documents and Settings")

On Windows, the second example above will be translated to C:/Documents and Settings when used to access files.

Examples of relative paths:

QDir("images/landscape.png")

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.

QDir("Documents/Letters/Applications").dirName() // "Applications"
QDir().dirName() // "."

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.

QDir directory("Documents/Letters");
QString path = directory.filePath("contents.txt");
QString absolutePath = directory.absoluteFilePath("contents.txt");

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:

QDir dir("example");
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:

QDir dir = QDir::root(); // "/"
if (!dir.cd("tmp")) { // "/tmp"
qWarning("Cannot find the \"/tmp\" directory");
} else {
QFile file(dir.filePath("ex1.txt")); // "/tmp/ex1.txt"
if (!file.open(QIODevice::ReadWrite))
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[])
{
QCoreApplication app(argc, argv);
QDir dir;
std::cout << " Bytes Filename" << std::endl;
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
std::cout << qPrintable(QString("%1 %2").arg(fileInfo.size(), 10)
.arg(fileInfo.fileName()));
std::cout << std::endl;
}
return 0;
}
See also
QFileInfo, QFile, QFileDialog, QApplication::applicationDirPath(), {Find Files Example}

Definition at line 58 of file qdir.h.

Enumerations

◆ Filter

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:

  • Dirs List directories that match the filters.
  • AllDirs List all directories; i.e. don't apply the filters to directory names.
  • Files List files.
  • Drives List disk drives (ignored under Unix).
  • NoSymLinks Do not list symbolic links (ignored by operating systems that don't support symbolic links).
  • NoDotAndDotDot Do not list the special entries "." and "..".
  • NoDot Do not list the special entry ".".
  • NoDotDot Do not list the special entry "..".
  • AllEntries List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System).
  • Readable List files for which the application has read access. The Readable value needs to be combined with Dirs or Files.
  • Writable List files for which the application has write access. The Writable value needs to be combined with Dirs or Files.
  • Executable List files for which the application has execute access. The Executable value needs to be combined with Dirs or Files.
  • Modified Only list files that have been modified (ignored on Unix).
  • Hidden List hidden files (on Unix, files starting with a ".").
  • System List system files (on Unix, FIFOs, sockets and device files are included; on Windows, {.lnk} files are included)
  • CaseSensitive The filter should be case sensitive.
  • DefaultFilter
  • TypeMask
  • All
  • RWEMask
  • AccessMask
  • PermissionMask
  • NoFilter

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.

Enumerator
Dirs 
Files 
Drives 
NoSymLinks 
AllEntries 
TypeMask 
Readable 
Writable 
Executable 
PermissionMask 
Modified 
Hidden 
System 
AccessMask 
AllDirs 
CaseSensitive 
NoDotAndDotDot 
NoDot 
NoDotDot 
NoFilter 

Definition at line 64 of file qdir.h.

64  { Dirs = 0x001,
65  Files = 0x002,
66  Drives = 0x004,
67  NoSymLinks = 0x008,
69  TypeMask = 0x00f,
70 #ifdef QT3_SUPPORT
71  All = AllEntries,
72 #endif
73 
74  Readable = 0x010,
75  Writable = 0x020,
76  Executable = 0x040,
77  PermissionMask = 0x070,
78 #ifdef QT3_SUPPORT
79  RWEMask = 0x070,
80 #endif
81 
82  Modified = 0x080,
83  Hidden = 0x100,
84  System = 0x200,
85 
86  AccessMask = 0x3F0,
87 
88  AllDirs = 0x400,
89  CaseSensitive = 0x800,
90  NoDotAndDotDot = 0x1000, // ### Qt5 NoDotAndDotDot = NoDot|NoDotDot
91  NoDot = 0x2000,
92  NoDotDot = 0x4000,
93 
94  NoFilter = -1
95 #ifdef QT3_SUPPORT
96  ,DefaultFilter = NoFilter
97 #endif
98  };

◆ SortFlag

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:

  • Name Sort by name.
  • Time Sort by time (modification time).
  • Size Sort by file size.
  • Type Sort by file type (extension).
  • Unsorted Do not sort.
  • NoSort Not sorted by default.
  • DirsFirst Put the directories first, then the files.
  • DirsLast Put the files first, then the directories.
  • Reversed Reverse the sort order.
  • IgnoreCase Sort case-insensitively.
  • LocaleAware Sort items appropriately using the current locale settings.
  • SortByMask
  • DefaultSort

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.

Enumerator
Name 
Time 
Size 
Unsorted 
SortByMask 
DirsFirst 
Reversed 
IgnoreCase 
DirsLast 
LocaleAware 
Type 
NoSort 

Definition at line 104 of file qdir.h.

104  { Name = 0x00,
105  Time = 0x01,
106  Size = 0x02,
107  Unsorted = 0x03,
108  SortByMask = 0x03,
109 
110  DirsFirst = 0x04,
111  Reversed = 0x08,
112  IgnoreCase = 0x10,
113  DirsLast = 0x20,
114  LocaleAware = 0x40,
115  Type = 0x80,
116  NoSort = -1
117 #ifdef QT3_SUPPORT
118  ,DefaultSort = NoSort
119 #endif
120  };

Constructors and Destructors

◆ QDir() [1/3]

QDir::QDir ( const QDir dir)

Constructs a QDir object that is a copy of the QDir object for directory dir.

See also
operator=()

Definition at line 561 of file qdir.cpp.

562  : d_ptr(dir.d_ptr)
563 {
564 }
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ QDir() [2/3]

QDir::QDir ( 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()

Definition at line 527 of file qdir.cpp.

527  : d_ptr(new QDirPrivate(path))
528 {
529 }
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ QDir() [3/3]

QDir::QDir ( 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(), setSorting()

Definition at line 549 of file qdir.cpp.

551  : d_ptr(new QDirPrivate(path, QDir::nameFiltersFromString(nameFilter), sort, filters))
552 {
553 }
static void sort(T *array, int count, LessThan lessThan)
static const char *const filters[3]
static QStringList nameFiltersFromString(const QString &nameFilter)
Returns a list of name filters from the given nameFilter.
Definition: qdir.cpp:2236
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ ~QDir()

QDir::~QDir ( )

Destroys the QDir object frees up its resources.

This has no effect on the underlying directory in the file system.

Definition at line 570 of file qdir.cpp.

571 {
572 }

Functions

◆ absoluteFilePath()

QString QDir::absoluteFilePath ( 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() canonicalPath()

Definition at line 701 of file qdir.cpp.

Referenced by QCoreApplication::applicationFilePath(), initializeDb(), QDeclarativeDebugServerPrivate::loadConnectionPlugin(), QDeclarativeInspectorService::loadInspectorPlugin(), QBasicUnixFontDatabase::populateFontDatabase(), QPlatformFontDatabase::populateFontDatabase(), and QDeclarativeImportDatabase::resolvePlugin().

702 {
703  const QDirPrivate* d = d_ptr.constData();
704  if (isAbsolutePath(fileName))
705  return fileName;
706 
708  if (fileName.isEmpty())
709  return d->absoluteDirEntry.filePath();
710  if (!d->absoluteDirEntry.isRoot())
711  return d->absoluteDirEntry.filePath() % QLatin1Char('/') % fileName;
712  return d->absoluteDirEntry.filePath() % fileName;
713 }
double d
Definition: qnumeric_p.h:62
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition: qdir.h:192
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void resolveAbsoluteEntry() const
Definition: qdir.cpp:194
QFileSystemEntry absoluteDirEntry
Definition: qdir_p.h:92
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ absolutePath()

QString QDir::absolutePath ( ) 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(), absoluteFilePath()

Definition at line 619 of file qdir.cpp.

Referenced by QDirModel::index(), makeAbsolute(), QDirModel::mkdir(), QFileSystemModel::mkdir(), QFileSystemModelPrivate::node(), QMovie::QMovie(), relativeFilePath(), QDeclarativeImportDatabase::resolvePlugin(), QNetworkDiskCache::setCacheDirectory(), QFileDialog::setDirectory(), and QMovie::setFileName().

620 {
621  const QDirPrivate* d = d_ptr.constData();
623  return d->absoluteDirEntry.filePath();
624 }
double d
Definition: qnumeric_p.h:62
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void resolveAbsoluteEntry() const
Definition: qdir.cpp:194
QFileSystemEntry absoluteDirEntry
Definition: qdir_p.h:92

◆ addResourceSearchPath()

void QDir::addResourceSearchPath ( 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}

Definition at line 989 of file qdir.cpp.

990 {
991 #ifdef QT_BUILD_CORE_LIB
993 #else
994  Q_UNUSED(path)
995 #endif
996 }
static void addSearchPath(const QString &path)
Use QDir::addSearchPath() with a prefix instead.
Definition: qresource.cpp:577
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ addSearchPath()

static void QDir::addSearchPath ( const QString prefix,
const QString path 
)
static

Referenced by addResourceSearchPath().

◆ canonicalPath()

QString QDir::canonicalPath ( ) 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:

QString bin = "/local/bin"; // where /local/bin is a symlink to /usr/bin
QDir binDir(bin);
QString canonicalBin = binDir.canonicalPath();
// canonicalBin now equals "/usr/bin"
QString ls = "/local/bin/ls"; // where ls is the executable "ls"
QDir lsDir(ls);
QString canonicalLs = lsDir.canonicalPath();
// canonicalLS now equals "/usr/bin/ls".
See also
path(), absolutePath(), exists(), cleanPath(), dirName(), absoluteFilePath()

Definition at line 642 of file qdir.cpp.

Referenced by QDeclarativeImportDatabase::addImportPath(), QCoreApplication::addLibraryPath(), QDeclarativeImportDatabase::addPluginPath(), QCoreApplicationPrivate::appendApplicationPathToLibraryPaths(), QScriptEngine::importExtension(), QCoreApplication::libraryPaths(), operator==(), QDeclarativeImportDatabase::QDeclarativeImportDatabase(), QCoreApplication::removeLibraryPath(), and QCoreApplication::setApplicationVersion().

643 {
644  const QDirPrivate* d = d_ptr.constData();
645  if (d->fileEngine.isNull()) {
647  return answer.filePath();
648  }
650 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
virtual QString fileName(FileName file=DefaultName) const
Return the file engine&#39;s current file name in the format specified by file.
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QString filePath() const
QFileSystemMetaData metaData
Definition: qdir_p.h:93
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)

◆ cd()

bool QDir::cd ( const QString dirName)

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(), path()

Definition at line 880 of file qdir.cpp.

Referenced by cdUp(), and QScriptEngine::importExtension().

881 {
882  // Don't detach just yet.
883  const QDirPrivate * const d = d_ptr.constData();
884 
885  if (dirName.isEmpty() || dirName == QLatin1String("."))
886  return true;
887  QString newPath;
888  if (isAbsolutePath(dirName)) {
889  newPath = cleanPath(dirName);
890  } else {
891  if (isRoot()) {
892  if (dirName == QLatin1String(".."))
893  return false;
894  newPath = d->dirEntry.filePath();
895  } else {
896  newPath = d->dirEntry.filePath() % QLatin1Char('/');
897  }
898 
899  newPath += dirName;
900  if (dirName.indexOf(QLatin1Char('/')) >= 0
901  || dirName == QLatin1String("..")
902  || d->dirEntry.filePath() == QLatin1String(".")) {
903  newPath = cleanPath(newPath);
904  /*
905  If newPath starts with .., we convert it to absolute to
906  avoid infinite looping on
907 
908  QDir dir(".");
909  while (dir.cdUp())
910  ;
911  */
912  if (newPath.startsWith(QLatin1String(".."))) {
913  newPath = QFileInfo(newPath).absoluteFilePath();
914  }
915  }
916  }
917 
919  dir->setPath(newPath);
920  if (!dir->exists())
921  return false;
922 
923  d_ptr = dir.take();
924  return true;
925 }
double d
Definition: qnumeric_p.h:62
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition: qdir.h:192
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
QString dirName() const
Returns the name of the directory; this is not the same as the path, e.g.
Definition: qdir.cpp:663
bool isRoot() const
Returns true if the directory is the root directory; otherwise returns false.
Definition: qdir.cpp:1577
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ cdUp()

bool QDir::cdUp ( )

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(), path()

Definition at line 937 of file qdir.cpp.

Referenced by QDnotifyFileSystemWatcherEngine::addPaths(), QFileSystemEngine::getLinkTarget(), QDirModel::mkdir(), and QDeclarativeFolderListModel::setFolder().

938 {
939  return cd(QString::fromLatin1(".."));
940 }
bool cd(const QString &dirName)
Changes the QDir&#39;s directory to dirName.
Definition: qdir.cpp:880
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ cleanPath()

QString QDir::cleanPath ( 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() canonicalPath()

Definition at line 2082 of file qdir.cpp.

Referenced by _q_resolveEntryAndCreateLegacyEngine_recursive(), _qt_get_directory(), QFileSystemEngine::absoluteName(), QUrlModel::addUrls(), QCoreApplication::applicationFilePath(), QFileSystemEngine::canonicalName(), cd(), cleanPath(), QFileSystemEngine::createDirectory(), QDirModel::filePath(), QLibraryInfoPrivate::findConfiguration(), QFileSystemEngine::getLinkTarget(), QFileSystemEngine::homePath(), isDirPath(), QLibraryInfo::location(), QFSFileEnginePrivate::longFileName(), QFileSystemEngine::nativeAbsoluteFilePath(), qt_resource_fixResourceRoot(), QFactoryLoader::refreshAll(), relativeFilePath(), QFileSystemEngine::removeDirectory(), QCoreApplication::removeLibraryPath(), QDirPrivate::resolveAbsoluteEntry(), QFileDialog::setDirectory(), QPluginLoader::setFileName(), QFileSystemModel::setRootPath(), QFileSystemEngine::slowCanonicalized(), QFileSystemEngine::tempPath(), and QFactoryLoader::updateDir().

2083 {
2084  if (path.isEmpty())
2085  return path;
2086  QString name = path;
2087  QChar dir_separator = separator();
2088  if (dir_separator != QLatin1Char('/'))
2089  name.replace(dir_separator, QLatin1Char('/'));
2090 
2091  int used = 0, levels = 0;
2092  const int len = name.length();
2093  QVarLengthArray<QChar> outVector(len);
2094  QChar *out = outVector.data();
2095 
2096  const QChar *p = name.unicode();
2097  for (int i = 0, last = -1, iwrite = 0; i < len; ++i) {
2098  if (p[i] == QLatin1Char('/')) {
2099  while (i+1 < len && p[i+1] == QLatin1Char('/')) {
2100 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) //allow unc paths
2101  if (!i)
2102  break;
2103 #endif
2104  i++;
2105  }
2106  bool eaten = false;
2107  if (i+1 < len && p[i+1] == QLatin1Char('.')) {
2108  int dotcount = 1;
2109  if (i+2 < len && p[i+2] == QLatin1Char('.'))
2110  dotcount++;
2111  if (i == len - dotcount - 1) {
2112  if (dotcount == 1) {
2113  break;
2114  } else if (levels) {
2115  if (last == -1) {
2116  for (int i2 = iwrite-1; i2 >= 0; i2--) {
2117  if (out[i2] == QLatin1Char('/')) {
2118  last = i2;
2119  break;
2120  }
2121  }
2122  }
2123  used -= iwrite - last - 1;
2124  break;
2125  }
2126  } else if (p[i+dotcount+1] == QLatin1Char('/')) {
2127  if (dotcount == 2 && levels) {
2128  if (last == -1 || iwrite - last == 1) {
2129  for (int i2 = (last == -1) ? (iwrite-1) : (last-1); i2 >= 0; i2--) {
2130  if (out[i2] == QLatin1Char('/')) {
2131  eaten = true;
2132  last = i2;
2133  break;
2134  }
2135  }
2136  } else {
2137  eaten = true;
2138  }
2139  if (eaten) {
2140  levels--;
2141  used -= iwrite - last;
2142  iwrite = last;
2143  last = -1;
2144  }
2145  } else if (dotcount == 2 && i > 0 && p[i - 1] != QLatin1Char('.')) {
2146  eaten = true;
2147  used -= iwrite - qMax(0, last);
2148  iwrite = qMax(0, last);
2149  last = -1;
2150  ++i;
2151  } else if (dotcount == 1) {
2152  eaten = true;
2153  }
2154  if (eaten)
2155  i += dotcount;
2156  } else {
2157  levels++;
2158  }
2159  } else if (last != -1 && iwrite - last == 1) {
2160 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
2161  eaten = (iwrite > 2);
2162 #else
2163  eaten = true;
2164 #endif
2165  last = -1;
2166  } else if (last != -1 && i == len-1) {
2167  eaten = true;
2168  } else {
2169  levels++;
2170  }
2171  if (!eaten)
2172  last = i - (i - iwrite);
2173  else
2174  continue;
2175  } else if (!i && p[i] == QLatin1Char('.')) {
2176  int dotcount = 1;
2177  if (len >= 1 && p[1] == QLatin1Char('.'))
2178  dotcount++;
2179  if (len >= dotcount && p[dotcount] == QLatin1Char('/')) {
2180  if (dotcount == 1) {
2181  i++;
2182  while (i+1 < len-1 && p[i+1] == QLatin1Char('/'))
2183  i++;
2184  continue;
2185  }
2186  }
2187  }
2188  out[iwrite++] = p[i];
2189  used++;
2190  }
2191 
2192  QString ret = (used == len ? name : QString(out, used));
2193  // Strip away last slash except for root directories
2194  if (ret.length() > 1 && ret.endsWith(QLatin1Char('/'))) {
2195 #if defined (Q_OS_WIN) || defined (Q_OS_SYMBIAN)
2196  if (!(ret.length() == 3 && ret.at(1) == QLatin1Char(':')))
2197 #endif
2198  ret.chop(1);
2199  }
2200 
2201  return ret;
2202 }
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
const QChar * unicode() const
Returns a &#39;\0&#39;-terminated Unicode representation of the string.
Definition: qstring.h:706
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const char * name
QString path() const
Returns the path.
Definition: qdir.cpp:605
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ convertSeparators()

QString QDir::convertSeparators ( const QString pathName)
static

Use QDir::toNativeSeparators() instead.

Definition at line 788 of file qdir.cpp.

789 {
790  return toNativeSeparators(pathName);
791 }
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812

◆ count()

uint QDir::count ( ) const

Returns the total number of directories and files in the directory.

Equivalent to entryList().count().

See also
operator[](), entryList()

Definition at line 1247 of file qdir.cpp.

Referenced by cleanupFontsDir(), initializeDb(), QBasicUnixFontDatabase::populateFontDatabase(), and QPlatformFontDatabase::populateFontDatabase().

1248 {
1249  const QDirPrivate* d = d_ptr.constData();
1250  d->initFileLists(*this);
1251  return d->files.count();
1252 }
double d
Definition: qnumeric_p.h:62
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QStringList files
Definition: qdir_p.h:88
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void initFileLists(const QDir &dir) const
Definition: qdir.cpp:324

◆ current()

QDir QDir::current ( )
inlinestatic

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(), temp()

Definition at line 209 of file qdir.h.

Referenced by _qt_get_directory(), and QCoreApplication::applicationFilePath().

209 { return QDir(currentPath()); }
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
Definition: qdir.cpp:561
static QString currentPath()
Returns the absolute path of the application&#39;s current directory.
Definition: qdir.cpp:1875

◆ currentPath()

QString QDir::currentPath ( )
static

◆ dirName()

QString QDir::dirName ( ) 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(), absoluteFilePath()

Definition at line 663 of file qdir.cpp.

Referenced by cd(), and QDirModel::mkdir().

664 {
665  const QDirPrivate* d = d_ptr.constData();
666  return d->dirEntry.fileName();
667 }
double d
Definition: qnumeric_p.h:62
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QString fileName() const
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ drives()

QFileInfoList QDir::drives ( )
static

Returns a list of the root directories on this system.

On Windows this returns a list of QFileInfo objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").

See also
root(), rootPath()

Definition at line 1812 of file qdir.cpp.

Referenced by QDirModelPrivate::children(), QFileInfoGatherer::getFileInfos(), and QPluginLoader::setFileName().

1813 {
1814 #ifdef QT_NO_FSFILEENGINE
1815  return QFileInfoList();
1816 #else
1817  return QFSFileEngine::drives();
1818 #endif
1819 }
QList< QFileInfo > QFileInfoList
Definition: qfileinfo.h:197
static QFileInfoList drives()
For Windows, returns the list of drives in the file system as a list of QFileInfo objects...

◆ entryInfoList() [1/2]

QFileInfoList QDir::entryInfoList ( 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().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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(), exists()

Definition at line 1316 of file qdir.cpp.

Referenced by QScriptEngine::availableExtensions(), QDirModelPrivate::children(), QBenchmarkValgrindUtils::cleanup(), QFontEngineQPF::cleanUpAfterClientCrash(), QDirModelPrivate::entryInfoList(), QBenchmarkValgrindUtils::getNewestFileName(), QScriptEngine::importExtension(), QScriptDebuggerConsolePrivate::loadScriptedCommands(), qt_parseEtcLpMember(), qt_parseEtcLpPrinters(), and qt_parseSpoolInterface().

1317 {
1318  const QDirPrivate* d = d_ptr.constData();
1319  return entryInfoList(d->nameFilters, filters, sort);
1320 }
double d
Definition: qnumeric_p.h:62
static void sort(T *array, int count, LessThan lessThan)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QFileInfoList entryInfoList(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().
Definition: qdir.cpp:1316
static const char *const filters[3]
QStringList nameFilters
Definition: qdir_p.h:76
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ entryInfoList() [2/2]

QFileInfoList QDir::entryInfoList ( 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(), exists()

Definition at line 1384 of file qdir.cpp.

1386 {
1387  const QDirPrivate* d = d_ptr.constData();
1388 
1389  if (filters == NoFilter)
1390  filters = d->filters;
1391 #ifdef QT3_SUPPORT
1392  if (d->matchAllDirs)
1393  filters |= AllDirs;
1394 #endif
1395  if (sort == NoSort)
1396  sort = d->sort;
1397 
1398  if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
1399  d->initFileLists(*this);
1400  return d->fileInfos;
1401  }
1402 
1403  QFileInfoList l;
1405  while (it.hasNext()) {
1406  it.next();
1407  l.append(it.fileInfo());
1408  }
1409  QFileInfoList ret;
1410  d->sortFileList(sort, l, 0, &ret);
1411  return ret;
1412 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
The QDirIterator class provides an iterator for directory entrylists.
Definition: qdiriterator.h:54
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static void sort(T *array, int count, LessThan lessThan)
QStringList nameFilters() const
Returns the string list set by setNameFilters()
Definition: qdir.cpp:945
static void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *)
Definition: qdir.cpp:294
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
static const char *const filters[3]
QStringList nameFilters
Definition: qdir_p.h:76
QDir::SortFlags sort
Definition: qdir_p.h:77
QFactoryLoader * l
QDir::Filters filters
Definition: qdir_p.h:78
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void initFileLists(const QDir &dir) const
Definition: qdir.cpp:324
QFileInfoList fileInfos
Definition: qdir_p.h:89

◆ entryList() [1/2]

QStringList QDir::entryList ( 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().

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

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(), setFilter()

Definition at line 1290 of file qdir.cpp.

Referenced by QCoreApplication::applicationFilePath(), QDirModelPrivate::entryList(), QPollingFileSystemWatcherEngine::FileInfo::FileInfo(), findAllLibCrypto(), findAllLibSsl(), QDeclarativeDebugServerPrivate::loadConnectionPlugin(), QDeclarativeInspectorService::loadInspectorPlugin(), QPollingFileSystemWatcherEngine::FileInfo::operator!=(), and QFactoryLoader::updateDir().

1291 {
1292  const QDirPrivate* d = d_ptr.constData();
1293  return entryList(d->nameFilters, filters, sort);
1294 }
double d
Definition: qnumeric_p.h:62
static void sort(T *array, int count, LessThan lessThan)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
static const char *const filters[3]
QStringList nameFilters
Definition: qdir_p.h:76
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
QStringList entryList(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 t...
Definition: qdir.cpp:1290

◆ entryList() [2/2]

QStringList QDir::entryList ( 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(), setFilter()

Definition at line 1338 of file qdir.cpp.

1340 {
1341  const QDirPrivate* d = d_ptr.constData();
1342 
1343  if (filters == NoFilter)
1344  filters = d->filters;
1345 #ifdef QT3_SUPPORT
1346  if (d->matchAllDirs)
1347  filters |= AllDirs;
1348 #endif
1349  if (sort == NoSort)
1350  sort = d->sort;
1351 
1352  if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
1353  d->initFileLists(*this);
1354  return d->files;
1355  }
1356 
1357  QFileInfoList l;
1359  while (it.hasNext()) {
1360  it.next();
1361  l.append(it.fileInfo());
1362  }
1363  QStringList ret;
1364  d->sortFileList(sort, l, &ret, 0);
1365  return ret;
1366 }
double d
Definition: qnumeric_p.h:62
#define it(className, varName)
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QStringList files
Definition: qdir_p.h:88
The QDirIterator class provides an iterator for directory entrylists.
Definition: qdiriterator.h:54
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
static void sort(T *array, int count, LessThan lessThan)
QStringList nameFilters() const
Returns the string list set by setNameFilters()
Definition: qdir.cpp:945
static void sortFileList(QDir::SortFlags, QFileInfoList &, QStringList *, QFileInfoList *)
Definition: qdir.cpp:294
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
static const char *const filters[3]
QStringList nameFilters
Definition: qdir_p.h:76
QDir::SortFlags sort
Definition: qdir_p.h:77
QFactoryLoader * l
QDir::Filters filters
Definition: qdir_p.h:78
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void initFileLists(const QDir &dir) const
Definition: qdir.cpp:324

◆ exists() [1/2]

bool QDir::exists ( ) const

Returns true if the directory exists; otherwise returns false.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

(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(), QFile::exists()

Definition at line 1560 of file qdir.cpp.

Referenced by QScriptEngine::availableExtensions(), QDeclarativeFolderListModel::componentComplete(), QIconLoader::findIconHelper(), QGuiPlatformPlugin::iconThemeSearchPaths(), QScriptEngine::importExtension(), QKde::kdeHome(), QDeclarativeDebugServerPrivate::loadConnectionPlugin(), QDeclarativeInspectorService::loadInspectorPlugin(), operator==(), qt_parseEtcLpMember(), qt_parseSpoolInterface(), qws_fontCacheDir(), and QFileSystemModel::setRootPath().

1561 {
1562  return d_ptr->exists();
1563 }
bool exists() const
Definition: qdir.cpp:131
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ exists() [2/2]

bool QDir::exists ( 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(), QFile::exists()

Definition at line 1794 of file qdir.cpp.

1795 {
1796  if (name.isEmpty()) {
1797  qWarning("QDir::exists: Empty or null file name");
1798  return false;
1799  }
1800  return QFile::exists(filePath(name));
1801 }
bool exists() const
Returns true if the file specified by fileName() exists; otherwise returns false. ...
Definition: qfile.cpp:626
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ filePath()

QString QDir::filePath ( 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(), canonicalPath()

Definition at line 678 of file qdir.cpp.

Referenced by exists(), QLibraryInfoPrivate::findConfiguration(), QIconLoader::findIconHelper(), mkdir(), mkpath(), remove(), rename(), rmdir(), rmpath(), and QFileInfo::setFile().

679 {
680  const QDirPrivate* d = d_ptr.constData();
681  if (isAbsolutePath(fileName))
682  return QString(fileName);
683 
684  QString ret = d->dirEntry.filePath();
685  if (!fileName.isEmpty()) {
686  if (!ret.isEmpty() && ret[(int)ret.length()-1] != QLatin1Char('/') && fileName[0] != QLatin1Char('/'))
687  ret += QLatin1Char('/');
688  ret += fileName;
689  }
690  return ret;
691 }
double d
Definition: qnumeric_p.h:62
static bool isAbsolutePath(const QString &path)
Returns true if path is absolute; returns false if it is relative.
Definition: qdir.h:192
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ filter()

QDir::Filters QDir::filter ( ) const

Returns the value set by setFilter()

Definition at line 1085 of file qdir.cpp.

Referenced by operator<<().

1086 {
1087  const QDirPrivate* d = d_ptr.constData();
1088  return d->filters;
1089 }
double d
Definition: qnumeric_p.h:62
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QDir::Filters filters
Definition: qdir_p.h:78
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ fromNativeSeparators()

QString QDir::fromNativeSeparators ( const QString pathName)
static

Returns pathName using '/' as file separator.

Since
4.2

On Windows, for instance, fromNativeSeparators("<tt>c:\\winnt\\system32</tt>") 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(), separator()

Definition at line 848 of file qdir.cpp.

Referenced by QZipWriter::addDirectory(), QZipWriter::addFile(), QZipWriter::addSymLink(), QFileSystemModelPrivate::filePath(), QUrl::fromLocalFile(), QFileInfoGatherer::getFileInfos(), isDirPath(), QFSFileEnginePrivate::longFileName(), QFileSystemModelPrivate::name(), QFileSystemEngine::nativeAbsoluteFilePath(), QFileSystemModelPrivate::node(), QFileSystemEntry::resolveFilePath(), QDirPrivate::setPath(), QFileSystemModel::setRootPath(), and QCompleter::splitPath().

849 {
850 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
851  int i = pathName.indexOf(QLatin1Char('\\'));
852  if (i != -1) {
853  QString n(pathName);
854 
855  QChar * const data = n.data();
856  data[i++] = QLatin1Char('/');
857 
858  for (; i < n.length(); ++i) {
859  if (data[i] == QLatin1Char('\\'))
860  data[i] = QLatin1Char('/');
861  }
862 
863  return n;
864  }
865 #endif
866  return pathName;
867 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ home()

QDir QDir::home ( )
inlinestatic

Returns the user's home directory.

The directory is constructed using the absolute path of the home directory, ensuring that its path() will be the same as its absolutePath().

See homePath() for details.

See also
drives(), current(), root(), temp()

Definition at line 212 of file qdir.h.

212 { return QDir(homePath()); }
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
Definition: qdir.cpp:561
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942

◆ homePath()

QString QDir::homePath ( )
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:

C:/Documents and Settings/Username

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:

  1. The path specified by the USERPROFILE environment variable.
  2. The path formed by concatenating the HOMEDRIVE and HOMEPATH environment variables.
  3. The path specified by the HOME environment variable.
  4. The path returned by the rootPath() function (which uses the SystemDrive environment variable)
  5. The C:/ directory.

Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath().

On Symbian this typically returns "c:/data", i.e. the same as native PathInfo::PhoneMemoryRootPath().

See also
home(), currentPath(), rootPath(), tempPath()

Definition at line 1942 of file qdir.cpp.

Referenced by QFileDialogPrivate::_q_goHome(), QMacPasteboardMimeVCard::convertFromMime(), QFileDialogPrivate::createWidgets(), QMacSettingsPrivate::fileName(), getFullPath(), QScanThread::getUserConfigurations(), QGuiPlatformPlugin::iconThemeSearchPaths(), QTestFileLogger::init(), initDefaultPaths(), QKde::kdeHome(), launchWebBrowser(), openDocument(), qt_getDefaultFromHomePrinters(), qt_parseNsswitchPrintersEntry(), qt_tildeExpansion(), qt_win_get_open_file_name(), qt_win_get_open_file_names(), qt_win_get_save_file_name(), QUnixPrintWidgetPrivate::QUnixPrintWidgetPrivate(), QUnixPrintWidgetPrivate::setupPrinter(), and QDesktopServices::storageLocation().

1943 {
1944  return QFileSystemEngine::homePath();
1945 }

◆ isAbsolute()

bool QDir::isAbsolute ( ) const
inline

Returns true if the directory's path is absolute; otherwise returns false.

See isAbsolutePath().

See also
isRelative() makeAbsolute() cleanPath()

Definition at line 194 of file qdir.h.

194 { return !isRelative(); }
bool isRelative() const
Returns true if the directory path is relative; otherwise returns false.
Definition: qdir.cpp:1615

◆ isAbsolutePath()

bool QDir::isAbsolutePath ( const QString path)
inlinestatic

Returns true if path is absolute; returns false if it is relative.

See also
isAbsolute() isRelativePath() makeAbsolute() cleanPath()

Definition at line 192 of file qdir.h.

Referenced by absoluteFilePath(), QmlApplicationViewerPrivate::adjustPath(), cd(), filePath(), QUrl::fromUserInput(), QProcessPrivate::pipeWriterBytesToWrite(), and qt_create_commandline().

192 { return !isRelativePath(path); }
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210

◆ isReadable()

bool QDir::isReadable ( ) 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()

Definition at line 1527 of file qdir.cpp.

1528 {
1529  const QDirPrivate* d = d_ptr.constData();
1530 
1531  if (d->fileEngine.isNull()) {
1534 
1535  return (d->metaData.permissions() & QFile::ReadUser) != 0;
1536  }
1537 
1538  const QAbstractFileEngine::FileFlags info =
1541  if (!(info & QAbstractFileEngine::DirectoryType))
1542  return false;
1543  return info & QAbstractFileEngine::ReadUserPerm;
1544 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
double d
Definition: qnumeric_p.h:62
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const
This function should return the set of OR&#39;d flags that are true for the file engine&#39;s file...
static mach_timebase_info_data_t info
QFile::Permissions permissions() const
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
bool hasFlags(MetaDataFlags flags) const
QFileSystemMetaData metaData
Definition: qdir_p.h:93
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ isRelative()

bool QDir::isRelative ( ) 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() cleanPath()

Definition at line 1615 of file qdir.cpp.

Referenced by QDirModel::mkdir().

1616 {
1617  if (d_ptr->fileEngine.isNull())
1618  return d_ptr->dirEntry.isRelative();
1619  return d_ptr->fileEngine->isRelativePath();
1620 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
virtual bool isRelativePath() const
Return true if the file referred to by this file engine has a relative path; otherwise return false...
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
bool isRelative() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ isRelativePath()

bool QDir::isRelativePath ( const QString path)
static

Returns true if path is relative; returns false if it is absolute.

See also
isRelative() isAbsolutePath() makeAbsolute()

Definition at line 2210 of file qdir.cpp.

Referenced by QDeclarativeTypeLoader::get(), QDeclarativeTypeLoader::getQmldir(), QDeclarativeTypeLoader::getScript(), QLibraryInfo::location(), makeAbsolute(), relativeFilePath(), QDeclarativeImportDatabase::resolvePlugin(), QFileDialog::selectFile(), QFileDialogPrivate::selectFile_sys(), and QUnixPrintWidgetPrivate::setupPrinter().

2211 {
2212  return QFileInfo(path).isRelative();
2213 }
bool isRelative() const
Returns true if the file path name is relative, otherwise returns false if the path is absolute (e...
Definition: qfileinfo.cpp:642
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ isRoot()

bool QDir::isRoot ( ) 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.

QDir dir("/tmp/root_link");
dir = dir.canonicalPath();
if (dir.isRoot())
qWarning("It is a root link");
See also
root(), rootPath()

Definition at line 1577 of file qdir.cpp.

Referenced by QDnotifyFileSystemWatcherEngine::addPaths(), cd(), and QDeclarativeFolderListModel::setFolder().

1578 {
1579  if (d_ptr->fileEngine.isNull())
1580  return d_ptr->dirEntry.isRoot();
1582 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
virtual FileFlags fileFlags(FileFlags type=FileInfoAll) const
This function should return the set of OR&#39;d flags that are true for the file engine&#39;s file...
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ makeAbsolute()

bool QDir::makeAbsolute ( )

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() cleanPath()

Definition at line 1630 of file qdir.cpp.

1631 {
1632  const QDirPrivate *d = d_ptr.constData();
1634  if (!d->fileEngine.isNull()) {
1636  if (QDir::isRelativePath(absolutePath))
1637  return false;
1638 
1639  dir.reset(new QDirPrivate(*d_ptr.constData()));
1640  dir->setPath(absolutePath);
1641  } else { // native FS
1642  d->resolveAbsoluteEntry();
1643  dir.reset(new QDirPrivate(*d_ptr.constData()));
1644  dir->setPath(d->absoluteDirEntry.filePath());
1645  }
1646  d_ptr = dir.take(); // actually detach
1647  return true;
1648 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
virtual QString fileName(FileName file=DefaultName) const
Return the file engine&#39;s current file name in the format specified by file.
void setPath(const QString &path)
Definition: qdir.cpp:168
T * take()
Returns the value of the pointer referenced by this object.
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
The QScopedPointer class stores a pointer to a dynamically allocated object, and deletes it upon dest...
QString absolutePath() 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.
Definition: qdir.cpp:619
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
void reset(T *other=0)
Deletes the existing object it is pointing to if any, and sets its pointer to other.
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void resolveAbsoluteEntry() const
Definition: qdir.cpp:194
QFileSystemEntry absoluteDirEntry
Definition: qdir_p.h:92

◆ match() [1/2]

bool QDir::match ( const QStringList filters,
const QString fileName 
)
static

Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

The matching is case insensitive.

See also
{QRegExp wildcard matching}, QRegExp::exactMatch() entryList() entryInfoList()

Definition at line 2047 of file qdir.cpp.

Referenced by match(), and QNSOpenSavePanelDelegate::panel:shouldShowFilename:.

2048 {
2049  for (QStringList::ConstIterator sit = filters.constBegin(); sit != filters.constEnd(); ++sit) {
2051  if (rx.exactMatch(fileName))
2052  return true;
2053  }
2054  return false;
2055 }
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
const_iterator ConstIterator
Qt-style synonym for QList::const_iterator.
Definition: qlist.h:279
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ match() [2/2]

bool QDir::match ( 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() entryInfoList()

Definition at line 2065 of file qdir.cpp.

2066 {
2067  return match(nameFiltersFromString(filter), fileName);
2068 }
static bool match(const QStringList &filters, const QString &fileName)
Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; othe...
Definition: qdir.cpp:2047
static QStringList nameFiltersFromString(const QString &nameFilter)
Returns a list of name filters from the given nameFilter.
Definition: qdir.cpp:2236

◆ mkdir()

bool QDir::mkdir ( const QString dirName) const

Creates a sub-directory called dirName.

Returns true on success; otherwise returns false.

If the directory already exists when this function is called, it will return false.

See also
rmdir()

Definition at line 1424 of file qdir.cpp.

Referenced by QDirModel::mkdir(), QFileSystemModel::mkdir(), and QNetworkDiskCachePrivate::prepareLayout().

1425 {
1426  const QDirPrivate* d = d_ptr.constData();
1427 
1428  if (dirName.isEmpty()) {
1429  qWarning("QDir::mkdir: Empty or null file name(s)");
1430  return false;
1431  }
1432 
1433  QString fn = filePath(dirName);
1434  if (d->fileEngine.isNull())
1436  return d->fileEngine->mkdir(fn, false);
1437 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const
Requests that the directory dirName be created.
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ mkpath()

bool QDir::mkpath ( 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.

If the path already exists when this function is called, it will return true.

See also
rmpath()

Definition at line 1477 of file qdir.cpp.

Referenced by DumpIDL(), QZipReader::extractAll(), QNetworkDiskCachePrivate::prepareLayout(), qmlsqldatabase_initDatabasesPath(), and qws_fontCacheDir().

1478 {
1479  const QDirPrivate* d = d_ptr.constData();
1480 
1481  if (dirPath.isEmpty()) {
1482  qWarning("QDir::mkpath: Empty or null file name(s)");
1483  return false;
1484  }
1485 
1486  QString fn = filePath(dirPath);
1487  if (d->fileEngine.isNull())
1489  return d->fileEngine->mkdir(fn, true);
1490 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
virtual bool mkdir(const QString &dirName, bool createParentDirectories) const
Requests that the directory dirName be created.
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ nameFilters()

QStringList QDir::nameFilters ( ) const

Returns the string list set by setNameFilters()

Definition at line 945 of file qdir.cpp.

Referenced by entryInfoList(), entryList(), nameFiltersFromString(), operator<<(), and setNameFilters().

946 {
947  const QDirPrivate* d = d_ptr.constData();
948  return d->nameFilters;
949 }
double d
Definition: qnumeric_p.h:62
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QStringList nameFilters
Definition: qdir_p.h:76
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ nameFiltersFromString()

QStringList QDir::nameFiltersFromString ( const QString nameFilter)
static

Returns a list of name filters from the given nameFilter.

Warning
This function is not part of the public interface.

(If there is more than one filter, each pair of filters is separated by a space or by a semicolon.)

Definition at line 2236 of file qdir.cpp.

Referenced by match().

2237 {
2238  return QDirPrivate::splitFilters(nameFilter);
2239 }
static QStringList splitFilters(const QString &nameFilter, QChar sep=0)
Definition: qdir.cpp:158

◆ operator!=()

bool QDir::operator!= ( const QDir dir) const
inline

Returns true if directory dir and this directory have different paths or different sort or filter settings; otherwise returns false.

Example:

// The current directory is "/usr/local"
QDir d1("/usr/local/bin");
d1.setFilter(QDir::Executable);
QDir d2("bin");
if (d1 != d2)
qDebug("They differ");

Definition at line 198 of file qdir.h.

198 { return !operator==(dir); }
bool operator==(const QDir &dir) const
Returns true if directory dir and this directory have the same path and their sort and filter setting...
Definition: qdir.cpp:1659

◆ operator=() [1/2]

QDir & QDir::operator= ( const QDir dir)

Makes a copy of the dir object and assigns it to this QDir object.

Definition at line 1707 of file qdir.cpp.

1708 {
1709  d_ptr = dir.d_ptr;
1710  return *this;
1711 }
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ operator=() [2/2]

QDir & QDir::operator= ( const QString path)

Sets the directory path to the given path.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Use setPath() instead.

Definition at line 1724 of file qdir.cpp.

1725 {
1726  d_ptr->setPath(path);
1727  return *this;
1728 }
void setPath(const QString &path)
Definition: qdir.cpp:168
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ operator==()

bool QDir::operator== ( const QDir dir) const

Returns true if directory dir and this directory have the same path and their sort and filter settings are the same; otherwise returns false.

Example:

// The current directory is "/usr/local"
QDir d1("/usr/local/bin");
QDir d2("bin");
if (d1 == d2)
qDebug("They're the same");

Definition at line 1659 of file qdir.cpp.

1660 {
1661  const QDirPrivate *d = d_ptr.constData();
1662  const QDirPrivate *other = dir.d_ptr.constData();
1663 
1664  if (d == other)
1665  return true;
1666  Qt::CaseSensitivity sensitive;
1667  if (d->fileEngine.isNull() || other->fileEngine.isNull()) {
1668  if (d->fileEngine.data() != other->fileEngine.data()) // one is native, the other is a custom file-engine
1669  return false;
1670 
1672  } else {
1673  if (d->fileEngine->caseSensitive() != other->fileEngine->caseSensitive())
1674  return false;
1676  }
1677 
1678  if (d->filters == other->filters
1679  && d->sort == other->sort
1680  && d->nameFilters == other->nameFilters) {
1681 
1682  // Assume directories are the same if path is the same
1683  if (d->dirEntry.filePath() == other->dirEntry.filePath())
1684  return true;
1685 
1686  if (exists()) {
1687  if (!dir.exists())
1688  return false; //can't be equal if only one exists
1689  // Both exist, fallback to expensive canonical path computation
1690  return canonicalPath().compare(dir.canonicalPath(), sensitive) == 0;
1691  } else {
1692  if (dir.exists())
1693  return false; //can't be equal if only one exists
1694  // Neither exists, compare absolute paths rather than canonical (which would be empty strings)
1695  d->resolveAbsoluteEntry();
1696  other->resolveAbsoluteEntry();
1697  return d->absoluteDirEntry.filePath().compare(other->absoluteDirEntry.filePath(), sensitive) == 0;
1698  }
1699  }
1700  return false;
1701 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
T * data() const
Returns the value of the pointer referenced by this object.
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
bool exists() const
Returns true if the directory exists; otherwise returns false.
Definition: qdir.cpp:1560
virtual bool caseSensitive() const
Should return true if the underlying file system is case-sensitive; otherwise return false...
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
CaseSensitivity
Definition: qnamespace.h:1451
int compare(const QString &s) const
Definition: qstring.cpp:5037
QStringList nameFilters
Definition: qdir_p.h:76
QDir::SortFlags sort
Definition: qdir_p.h:77
QString canonicalPath() const
Returns the canonical path, i.e.
Definition: qdir.cpp:642
QDir::Filters filters
Definition: qdir_p.h:78
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void resolveAbsoluteEntry() const
Definition: qdir.cpp:194
QFileSystemEntry absoluteDirEntry
Definition: qdir_p.h:92

◆ operator[]()

QString QDir::operator[] ( int  pos) const

Returns the file name at position pos in the list of file names.

Equivalent to entryList().at(index). pos must be a valid index position in the list (i.e., 0 <= pos < count()).

See also
count(), entryList()

Definition at line 1261 of file qdir.cpp.

1262 {
1263  const QDirPrivate* d = d_ptr.constData();
1264  d->initFileLists(*this);
1265  return d->files[pos];
1266 }
double d
Definition: qnumeric_p.h:62
QStringList files
Definition: qdir_p.h:88
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
void initFileLists(const QDir &dir) const
Definition: qdir.cpp:324

◆ path()

QString QDir::path ( ) 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(), makeAbsolute()

Definition at line 605 of file qdir.cpp.

Referenced by QDnotifyFileSystemWatcherEngine::addPaths(), addResourceSearchPath(), cleanPath(), QGuiPlatformPlugin::iconThemeSearchPaths(), operator<<(), QIconTheme::QIconTheme(), QFileDialog::selectFile(), QDeclarativeFolderListModel::setFolder(), and QFileSystemModel::setRootPath().

606 {
607  const QDirPrivate* d = d_ptr.constData();
608  return d->dirEntry.filePath();
609 }
double d
Definition: qnumeric_p.h:62
QFileSystemEntry dirEntry
Definition: qdir_p.h:91
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QString filePath() const
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ refresh()

void QDir::refresh ( ) const

Refreshes the directory information.

Definition at line 2218 of file qdir.cpp.

Referenced by initializeDb(), QBasicUnixFontDatabase::populateFontDatabase(), and QPlatformFontDatabase::populateFontDatabase().

2219 {
2220  QDirPrivate *d = const_cast<QDir*>(this)->d_ptr.data();
2221  d->metaData.clear();
2222  d->initFileEngine();
2223  d->clearFileLists();
2224 }
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
double d
Definition: qnumeric_p.h:62
T * data()
Returns a pointer to the shared data object.
Definition: qshareddata.h:82
void initFileEngine()
Definition: qdir.cpp:338
void clearFileLists()
Definition: qdir.cpp:187
QFileSystemMetaData metaData
Definition: qdir_p.h:93
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ relativeFilePath()

QString QDir::relativeFilePath ( const QString fileName) const

Returns the path to fileName relative to the directory.

QDir dir("/home/bob");
s = dir.relativeFilePath("images/file.jpg"); // s is "images/file.jpg"
s = dir.relativeFilePath("/home/mary/file.txt"); // s is "../mary/file.txt"
See also
absoluteFilePath() filePath() canonicalPath()

Definition at line 722 of file qdir.cpp.

Referenced by QScriptEngine::availableExtensions().

723 {
724  QString dir = cleanPath(absolutePath());
725  QString file = cleanPath(fileName);
726 
727  if (isRelativePath(file) || isRelativePath(dir))
728  return file;
729 
730  QString dirDrive = driveSpec(dir);
731  QString fileDrive = driveSpec(file);
732 
733  bool fileDriveMissing = false;
734  if (fileDrive.isEmpty()) {
735  fileDrive = dirDrive;
736  fileDriveMissing = true;
737  }
738 
739 #ifdef Q_OS_WIN
740  if (fileDrive.toLower() != dirDrive.toLower()
741  || (file.startsWith(QLatin1String("//"))
742  && !dir.startsWith(QLatin1String("//"))))
743 #elif defined(Q_OS_SYMBIAN)
744  if (fileDrive.toLower() != dirDrive.toLower())
745 #else
746  if (fileDrive != dirDrive)
747 #endif
748  return file;
749 
750  dir.remove(0, dirDrive.size());
751  if (!fileDriveMissing)
752  file.remove(0, fileDrive.size());
753 
754  QString result;
756  QStringList fileElts = file.split(QLatin1Char('/'), QString::SkipEmptyParts);
757 
758  int i = 0;
759  while (i < dirElts.size() && i < fileElts.size() &&
760 #if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN)
761  dirElts.at(i).toLower() == fileElts.at(i).toLower())
762 #else
763  dirElts.at(i) == fileElts.at(i))
764 #endif
765  ++i;
766 
767  for (int j = 0; j < dirElts.size() - i; ++j)
768  result += QLatin1String("../");
769 
770  for (int j = i; j < fileElts.size(); ++j) {
771  result += fileElts.at(j);
772  if (j < fileElts.size() - 1)
773  result += QLatin1Char('/');
774  }
775 
776  return result;
777 }
static QString driveSpec(const QString &path)
Definition: qdir.cpp:71
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool isRelativePath(const QString &path)
Returns true if path is relative; returns false if it is absolute.
Definition: qdir.cpp:2210
The QString class provides a Unicode character string.
Definition: qstring.h:83
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString absolutePath() 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.
Definition: qdir.cpp:619
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
Definition: qdir.cpp:2082
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
Definition: qstring.cpp:5389
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ remove()

bool QDir::remove ( const QString fileName)

Removes the file, fileName.

Returns true if the file is removed successfully; otherwise returns false.

Definition at line 1751 of file qdir.cpp.

Referenced by cleanupFontsDir(), and QDirModel::remove().

1752 {
1753  if (fileName.isEmpty()) {
1754  qWarning("QDir::remove: Empty or null file name");
1755  return false;
1756  }
1757  return QFile::remove(filePath(fileName));
1758 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
bool remove()
Removes the file specified by fileName().
Definition: qfile.cpp:715
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ rename()

bool QDir::rename ( 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.

Definition at line 1771 of file qdir.cpp.

Referenced by QDirModel::setData(), and QFileSystemModel::setData().

1772 {
1773  if (oldName.isEmpty() || newName.isEmpty()) {
1774  qWarning("QDir::rename: Empty or null file name(s)");
1775  return false;
1776  }
1777 
1778  QFile file(filePath(oldName));
1779  if (!file.exists())
1780  return false;
1781  return file.rename(filePath(newName));
1782 }
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
The QFile class provides an interface for reading from and writing to files.
Definition: qfile.h:65
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ rmdir()

bool QDir::rmdir ( 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()

Definition at line 1448 of file qdir.cpp.

Referenced by QDirModel::rmdir(), and QFileSystemModel::rmdir().

1449 {
1450  const QDirPrivate* d = d_ptr.constData();
1451 
1452  if (dirName.isEmpty()) {
1453  qWarning("QDir::rmdir: Empty or null file name(s)");
1454  return false;
1455  }
1456 
1457  QString fn = filePath(dirName);
1458  if (d->fileEngine.isNull())
1460 
1461  return d->fileEngine->rmdir(fn, false);
1462 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const
Requests that the directory dirName is deleted from the file system.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ rmpath()

bool QDir::rmpath ( 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()

Definition at line 1503 of file qdir.cpp.

1504 {
1505  const QDirPrivate* d = d_ptr.constData();
1506 
1507  if (dirPath.isEmpty()) {
1508  qWarning("QDir::rmpath: Empty or null file name(s)");
1509  return false;
1510  }
1511 
1512  QString fn = filePath(dirPath);
1513  if (d->fileEngine.isNull())
1515  return d->fileEngine->rmdir(fn, true);
1516 }
bool isNull() const
Returns true if this object is holding a pointer that is null.
double d
Definition: qnumeric_p.h:62
virtual bool rmdir(const QString &dirName, bool recurseParentDirectories) const
Requests that the directory dirName is deleted from the file system.
The QString class provides a Unicode character string.
Definition: qstring.h:83
QScopedPointer< QAbstractFileEngine > fileEngine
Definition: qdir_p.h:85
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61
QString filePath(const QString &fileName) const
Returns the path name of a file in the directory.
Definition: qdir.cpp:678

◆ root()

QDir QDir::root ( )
inlinestatic

Returns the root directory.

The directory is constructed using the absolute path of the root directory, ensuring that its path() will be the same as its absolutePath().

See rootPath() for details.

See also
drives(), current(), home(), temp()

Definition at line 214 of file qdir.h.

Referenced by QZipReader::extractAll().

214 { return QDir(rootPath()); }
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
Definition: qdir.cpp:561
static QString rootPath()
Returns the absolute path of the root directory.
Definition: qdir.cpp:2016

◆ rootPath()

QString QDir::rootPath ( )
static

Returns the absolute path of the root directory.

For Unix operating systems this returns "/". For Windows and Symbian file systems this normally returns "c:/". I.E. the root of the system drive.

See also
root(), drives(), currentPath(), homePath(), tempPath()

Definition at line 2016 of file qdir.cpp.

Referenced by QFileSystemModelPrivate::node().

2017 {
2018  return QFileSystemEngine::rootPath();
2019 }

◆ searchPaths()

static QStringList QDir::searchPaths ( const QString prefix)
static

◆ separator()

QChar QDir::separator ( )
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().

Definition at line 1831 of file qdir.cpp.

Referenced by QCompleterPrivate::_q_complete(), QFileDialogPrivate::_q_createDirectory(), QScriptEngine::availableExtensions(), QFileDialogPrivate::basename(), QDeclarativeEngine::baseUrl(), QDirModelPrivate::children(), cleanPath(), QFileSystemEngine::createDirectory(), QDirModel::dropMimeData(), QFileSystemModel::dropMimeData(), QZipReader::extractAll(), QFileSystemModelPrivate::filePath(), QCompletionEngine::filterHistory(), QFileInfoGatherer::getFileInfos(), QScriptEngine::importExtension(), QTestFileLogger::init(), initDefaultPaths(), isDirPath(), QTextDocument::loadResource(), QFileSystemModel::mkdir(), QFSCompleter::pathFromIndex(), QCompleter::pathFromIndex(), QConfFileSettingsPrivate::QConfFileSettingsPrivate(), QDeclarativeImportDatabase::QDeclarativeImportDatabase(), QDeclarativeScriptEngine::QDeclarativeScriptEngine(), qmlsqldatabase_databaseFile(), qmlsqldatabase_databasesPath(), qt_tildeExpansion(), QFileSystemEngine::removeDirectory(), QTextBrowserPrivate::resolveUrl(), QFileDialog::selectFile(), QCoreApplication::setApplicationVersion(), QFileSystemModel::setData(), QSettings::setPath(), QUnixPrintWidgetPrivate::setupPrinter(), QFSCompleter::splitPath(), QCompleter::splitPath(), QFileDialogPrivate::typedFiles(), and QFileInfoGatherer::updateFile().

1832 {
1833 #if defined (Q_FS_FAT) || defined(Q_WS_WIN) || defined(Q_OS_SYMBIAN)
1834  return QLatin1Char('\\');
1835 #elif defined(Q_OS_UNIX)
1836  return QLatin1Char('/');
1837 #elif defined (Q_OS_MAC)
1838  return QLatin1Char(':');
1839 #else
1840  return QLatin1Char('/');
1841 #endif
1842 }
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ setCurrent()

bool QDir::setCurrent ( 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(), temp()

Definition at line 1851 of file qdir.cpp.

Referenced by qt_init().

1852 {
1854 }
static bool setCurrentPath(const QFileSystemEntry &entry)

◆ setFilter()

void QDir::setFilter ( 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(), setNameFilters()

Definition at line 1170 of file qdir.cpp.

Referenced by QFileDialogPrivate::_q_showHidden(), and QFileSystemModel::rootDirectory().

1171 {
1172  QDirPrivate* d = d_ptr.data();
1173  d->initFileEngine();
1174  d->clearFileLists();
1175 
1176  d->filters = filters;
1177 }
double d
Definition: qnumeric_p.h:62
T * data()
Returns a pointer to the shared data object.
Definition: qshareddata.h:82
void initFileEngine()
Definition: qdir.cpp:338
static const char *const filters[3]
void clearFileLists()
Definition: qdir.cpp:187
QDir::Filters filters
Definition: qdir_p.h:78
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ setNameFilters()

void QDir::setNameFilters ( 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:

filters << "*.cpp" << "*.cxx" << "*.cc";
dir.setNameFilters(filters);
See also
nameFilters(), setFilter()

Definition at line 966 of file qdir.cpp.

Referenced by initializeDb(), QBasicUnixFontDatabase::populateFontDatabase(), QPlatformFontDatabase::populateFontDatabase(), QFileSystemModel::rootDirectory(), and QSslSocketPrivate::systemCaCertificates().

967 {
968  QDirPrivate* d = d_ptr.data();
969  d->initFileEngine();
970  d->clearFileLists();
971 
973 }
double d
Definition: qnumeric_p.h:62
T * data()
Returns a pointer to the shared data object.
Definition: qshareddata.h:82
void initFileEngine()
Definition: qdir.cpp:338
QStringList nameFilters() const
Returns the string list set by setNameFilters()
Definition: qdir.cpp:945
QStringList nameFilters
Definition: qdir_p.h:76
void clearFileLists()
Definition: qdir.cpp:187
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ setPath()

void QDir::setPath ( 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(), makeAbsolute()

Definition at line 590 of file qdir.cpp.

Referenced by qt_win_get_open_file_names(), QDeclarativeFolderListModel::setFolder(), QFileSystemModel::setRootPath(), and QSslSocketPrivate::systemCaCertificates().

591 {
592  d_ptr->setPath(path);
593 }
void setPath(const QString &path)
Definition: qdir.cpp:168
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ setSearchPaths()

static void QDir::setSearchPaths ( const QString prefix,
const QStringList searchPaths 
)
static

Referenced by addResourceSearchPath().

◆ setSorting()

void QDir::setSorting ( SortFlags  sort)

Sets the sort order used by entryList() and entryInfoList().

The sort is specified by OR-ing values from the enum QDir::SortFlag.

See also
sorting() SortFlag

Definition at line 1231 of file qdir.cpp.

1232 {
1233  QDirPrivate* d = d_ptr.data();
1234  d->initFileEngine();
1235  d->clearFileLists();
1236 
1237  d->sort = sort;
1238 }
double d
Definition: qnumeric_p.h:62
T * data()
Returns a pointer to the shared data object.
Definition: qshareddata.h:82
void initFileEngine()
Definition: qdir.cpp:338
static void sort(T *array, int count, LessThan lessThan)
QDir::SortFlags sort
Definition: qdir_p.h:77
void clearFileLists()
Definition: qdir.cpp:187
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ sorting()

QDir::SortFlags QDir::sorting ( ) const

Returns the value set by setSorting()

See also
setSorting() SortFlag

Definition at line 1184 of file qdir.cpp.

Referenced by operator<<().

1185 {
1186  const QDirPrivate* d = d_ptr.constData();
1187  return d->sort;
1188 }
double d
Definition: qnumeric_p.h:62
const T * constData() const
Returns a const pointer to the shared data object.
Definition: qshareddata.h:84
QDir::SortFlags sort
Definition: qdir_p.h:77
QSharedDataPointer< QDirPrivate > d_ptr
Definition: qdir.h:61

◆ temp()

QDir QDir::temp ( )
inlinestatic

Returns the system's temporary directory.

The directory is constructed using the absolute path of the temporary directory, ensuring that its path() will be the same as its absolutePath().

See tempPath() for details.

See also
drives(), current(), home(), root()

Definition at line 216 of file qdir.h.

216 { return QDir(tempPath()); }
QDir(const QDir &)
Constructs a QDir object that is a copy of the QDir object for directory dir.
Definition: qdir.cpp:561
static QString tempPath()
Returns the absolute path of the system&#39;s temporary directory.
Definition: qdir.cpp:1987

◆ tempPath()

QString QDir::tempPath ( )
static

Returns the absolute path of the system's temporary directory.

On Unix/Linux systems this is the path in the TMPDIR environment variable or /tmp if TMPDIR is not defined. 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(), rootPath()

Definition at line 1987 of file qdir.cpp.

Referenced by QFile::copy(), getFullPath(), launchWebBrowser(), QSharedMemoryPrivate::makePlatformSafeKey(), openDocument(), QTemporaryFile::QTemporaryFile(), qws_fontCacheDir(), QSslSocketBackendPrivate::startHandshake(), QDesktopServices::storageLocation(), and QTemporaryFilePrivate::~QTemporaryFilePrivate().

1988 {
1989  return QFileSystemEngine::tempPath();
1990 }

◆ toNativeSeparators()

QString QDir::toNativeSeparators ( const QString pathName)
static

Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

Since
4.2

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(), separator()

Definition at line 812 of file qdir.cpp.

Referenced by QFileDialogPrivate::_q_pathChanged(), QWindowsFileSystemWatcherEngine::addPaths(), QFileDialogPrivate::basename(), QWindowsMimeURI::convertFromMime(), convertSeparators(), QCompletionEngine::filterHistory(), QFileIconProviderPrivate::getWinIcon(), QFileDialog::history(), QTestFileLogger::init(), isDirPath(), QLibraryPrivate::isPlugin(), isUncRoot(), QTranslator::load(), QFileSystemEngine::nativeAbsoluteFilePath(), QFileSystemModelPrivate::node(), qmlsqldatabase_databasesPath(), qt_create_commandline(), qt_win_get_existing_directory(), qt_win_get_save_file_name(), qt_win_make_OFN(), QFactoryLoader::refreshAll(), QFileSystemEntry::resolveNativeFilePath(), QUrlModel::setData(), QFileSystemModel::setData(), QPluginLoader::setFileName(), QFileDialogComboBox::setHistory(), QUrlModel::setUrl(), QFSCompleter::splitPath(), and QCompleter::splitPath().

813 {
814 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
815  int i = pathName.indexOf(QLatin1Char('/'));
816  if (i != -1) {
817  QString n(pathName);
818 
819  QChar * const data = n.data();
820  data[i++] = QLatin1Char('\\');
821 
822  for (; i < n.length(); ++i) {
823  if (data[i] == QLatin1Char('/'))
824  data[i] = QLatin1Char('\\');
825  }
826 
827  return n;
828  }
829 #endif
830  return pathName;
831 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static const char * data(const QByteArray &arr)
int indexOf(QChar c, int from=0, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:2838
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

Properties

◆ d_ptr

QSharedDataPointer<QDirPrivate> QDir::d_ptr
protected

The documentation for this class was generated from the following files: