⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdir.cpp

📁 QT 开发环境里面一个很重要的文件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Returns true if successful; otherwise returns false.    \sa mkdir()*/bool QDir::rmdir(const QString &dirName) const{    Q_D(const QDir);    if (dirName.isEmpty()) {        qWarning("QDir::rmdir: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirName);    return d->data->fileEngine->rmdir(fn, false);}/*!    Creates the directory path \a dirPath.    The function will create all parent directories necessary to    create the directory.    Returns true if successful; otherwise returns false.    \sa rmpath()*/bool QDir::mkpath(const QString &dirPath) const{    Q_D(const QDir);    if (dirPath.isEmpty()) {        qWarning("QDir::mkpath: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirPath);    return d->data->fileEngine->mkdir(fn, true);}/*!    Removes the directory path \a dirPath.    The function will remove all parent directories in \a dirPath,    provided that they are empty. This is the opposite of    mkpath(dirPath).    Returns true if successful; otherwise returns false.    \sa mkpath()*/bool QDir::rmpath(const QString &dirPath) const{    Q_D(const QDir);    if (dirPath.isEmpty()) {        qWarning("QDir::rmpath: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QString fn = filePath(dirPath);    return d->data->fileEngine->rmdir(fn, true);}/*!    Returns true if the directory is readable \e 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.    \sa QFileInfo::isReadable()*/bool QDir::isReadable() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return false;    const QAbstractFileEngine::FileFlags info = d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType                                                                       |QAbstractFileEngine::PermsMask);    if(!(info & QAbstractFileEngine::DirectoryType))        return false;    return info & QAbstractFileEngine::ReadUserPerm;}/*!    \overload    Returns true if the \e directory exists; otherwise returns false.    (If a file with the same name is found this function will return    false).    \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return false;    const QAbstractFileEngine::FileFlags info = d->data->fileEngine->fileFlags(QAbstractFileEngine::DirectoryType                                                                       |QAbstractFileEngine::ExistsFlag);    if(!(info & QAbstractFileEngine::DirectoryType))        return false;    return info & QAbstractFileEngine::ExistsFlag;}/*!    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.    \code        QDir dir("/tmp/root_link");        dir = dir.canonicalPath();        if (dir.isRoot())            qWarning("It is a root link");    \endcode    \sa root(), rootPath()*/bool QDir::isRoot() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return true;    return d->data->fileEngine->fileFlags(QAbstractFileEngine::FlagsMask) & QAbstractFileEngine::RootFlag;}/*!    \fn bool QDir::isAbsolute() const    Returns true if the directory's path is absolute; otherwise    returns false. See isAbsolutePath().    \sa isRelative() makeAbsolute() cleanPath()*//*!   \fn bool QDir::isAbsolutePath(const QString &)    Returns true if \a path is absolute; returns false if it is    relative.    \sa isAbsolute() isRelativePath() makeAbsolute() cleanPath()*//*!    Returns true if the directory path is relative; otherwise returns    false. (Under Unix a path is relative if it does not start with a    "/").    \sa makeAbsolute() isAbsolute() isAbsolutePath() cleanPath()*/bool QDir::isRelative() const{    Q_D(const QDir);    if(!d->data->fileEngine)        return false;    return d->data->fileEngine->isRelativePath();}/*!    Converts the directory path to an absolute path. If it is already    absolute nothing happens. Returns true if the conversion    succeeded; otherwise returns false.    \sa isAbsolute() isAbsolutePath() isRelative() cleanPath()*/bool QDir::makeAbsolute() // ### What do the return values signify?{    Q_D(QDir);    if(!d->data->fileEngine)        return false;    QString absolutePath = d->data->fileEngine->fileName(QAbstractFileEngine::AbsoluteName);    if(QDir::isRelativePath(absolutePath))        return false;    d->detach();    d->data->path = absolutePath;    d->data->fileEngine->setFileName(absolutePath);    if(!(d->data->fileEngine->fileFlags(QAbstractFileEngine::TypesMask) & QAbstractFileEngine::DirectoryType))        return false;    return true;}/*!    Returns true if directory \a dir and this directory have the same    path and their sort and filter settings are the same; otherwise    returns false.    Example:    \code        // The current directory is "/usr/local"        QDir d1("/usr/local/bin");        QDir d2("bin");        if (d1 == d2)            qDebug("They're the same");    \endcode*/bool QDir::operator==(const QDir &dir) const{    const QDirPrivate *d = d_func();    const QDirPrivate *other = dir.d_func();    if(d->data == other->data)        return true;    Q_ASSERT(d->data->fileEngine && other->data->fileEngine);    if(d->data->fileEngine->caseSensitive() != other->data->fileEngine->caseSensitive())        return false;    if(d->data->filters == other->data->filters       && d->data->sort == other->data->sort       && d->data->nameFilters == other->data->nameFilters) {        QString dir1 = absolutePath(), dir2 = dir.absolutePath();        if(!other->data->fileEngine->caseSensitive())            return (dir1.toLower() == dir2.toLower());        return (dir1 == dir2);    }    return false;}/*!    Makes a copy of the \a dir object and assigns it to this QDir    object.*/QDir &QDir::operator=(const QDir &dir){    if (this == &dir)        return *this;    Q_D(QDir);    qAtomicAssign(d->data, dir.d_func()->data);    return *this;}/*!    \overload    \obsolete    Sets the directory path to the given \a path.    Use setPath() instead.*/QDir &QDir::operator=(const QString &path){    Q_D(QDir);    d->setPath(path);    return *this;}/*!    \fn bool QDir::operator!=(const QDir &dir) const    Returns true if directory \a dir and this directory have different    paths or different sort or filter settings; otherwise returns    false.    Example:    \code        // The current directory is "/usr/local"        QDir d1("/usr/local/bin");        QDir d2("bin");        if (d1 != d2)            qDebug("They differ");    \endcode*//*!    Removes the file, \a fileName.    Returns true if the file is removed successfully; otherwise    returns false.*/bool QDir::remove(const QString &fileName){    if (fileName.isEmpty()) {        qWarning("QDir::remove: Empty or null file name");        return false;    }    QString p = filePath(fileName);    return QFile::remove(p);}/*!    Renames a file or directory from \a oldName to \a newName, and returns    true if successful; otherwise returns false.    On most file systems, rename() fails only if \a oldName does not    exist, if \a newName and \a 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    \a newName points to an open file.*/bool QDir::rename(const QString &oldName, const QString &newName){    Q_D(QDir);    if (oldName.isEmpty() || newName.isEmpty()) {        qWarning("QDir::rename: Empty or null file name(s)");        return false;    }    if(!d->data->fileEngine)        return false;    QFile file(filePath(oldName));    if(!file.exists())        return false;    return file.rename(filePath(newName));}/*!    Returns true if the file called \a name exists; otherwise returns    false.    \sa QFileInfo::exists(), QFile::exists()*/bool QDir::exists(const QString &name) const{    if (name.isEmpty()) {        qWarning("QDir::exists: Empty or null file name");        return false;    }    QString tmp = filePath(name);    return QFile::exists(tmp);}/*!    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. "/").    \sa root(), rootPath()*/QFileInfoList QDir::drives(){    return QFSFileEngine::drives();}/*!    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().*/QChar QDir::separator(){#if defined(Q_OS_UNIX)    return QLatin1Char('/');#elif defined (Q_FS_FAT) || defined(Q_WS_WIN)    return QLatin1Char('\\');#elif defined (Q_OS_MAC)    return QLatin1Char(':');#else    return QLatin1Char('/');#endif}/*!    Sets the application's current working directory to \a path.    Returns true if the directory was successfully changed; otherwise    returns false.    \sa current() currentPath() home() root() temp()*/bool QDir::setCurrent(const QString &path){    return QFSFileEngine::setCurrentPath(path);}/*!    \fn QDir QDir::current()    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().    \sa currentPath(), home(), root(), temp()*//*!    Returns the absolute path of the application's current directory.    \sa current(), homePath(), rootPath(), tempPath()*/QString QDir::currentPath(){    return QFSFileEngine::currentPath();}/*!    \fn QDir QDir::home()    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.    \sa drives(), current(), root(), temp()*//*!    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:    \code        C:\Documents and Settings\Username    \endcode

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -