?? qfileinfo.cpp
字號:
} return false;}/*! Returns true if this QFileInfo object refers to a file in the same location as \a fileinfo; otherwise returns false. Note that the result of comparing two empty QFileInfo objects, containing no file references, is undefined. \warning This will not compare two different symbolic links pointing to the same file. \warning Long and short file names that refer to the same file on Windows are treated as if they referred to different files. \sa operator!=()*/bool QFileInfo::operator==(const QFileInfo &fileinfo){ return const_cast<const QFileInfo *>(this)->operator==(fileinfo);}/*! Makes a copy of the given \a fileinfo and assigns it to this QFileInfo.*/QFileInfo &QFileInfo::operator=(const QFileInfo &fileinfo){ Q_D(QFileInfo); qAtomicAssign(d->data, fileinfo.d_func()->data); return *this;}/*! Sets the file that the QFileInfo provides information about to \a file. The \a file can also include an absolute or relative file path. Absolute paths begin with the directory separator (e.g. "/" under Unix) or 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. Example: \code QString absolute = "/local/bin"; QString relative = "local/bin"; QFileInfo absFile(absolute); QFileInfo relFile(relative); QDir::setCurrent(QDir::rootPath()); // absFile and relFile now point to the same file QDir::setCurrent("/tmp"); // absFile now points to "/local/bin", // while relFile points to "/tmp/local/bin" \endcode \sa isRelative(), QDir::setCurrent(), QDir::isRelativePath()*/voidQFileInfo::setFile(const QString &file){ Q_D(QFileInfo); d->initFileEngine(file);}/*! \overload Sets the file that the QFileInfo provides information about to \a file. If \a file includes a relative path, the QFileInfo will also have a relative path. \sa isRelative()*/voidQFileInfo::setFile(const QFile &file){ Q_D(QFileInfo); d->initFileEngine(file.fileName());}/*! \overload Sets the file that the QFileInfo provides information about to \a file in directory \a dir. If \a file includes a relative path, the QFileInfo will also have a relative path. \sa isRelative()*/voidQFileInfo::setFile(const QDir &dir, const QString &file){ Q_D(QFileInfo); d->initFileEngine(dir.filePath(file));}/*! Returns the absolute path including the file name. The absolute path name consists of the full path and the file name. On Unix this will always begin with the root, '/', directory. On Windows this will always begin 'D:/' where D is a drive letter, except for network shares that are not mapped to a drive letter, in which case the path will begin '//sharename/'. This function returns the same as filePath(), unless isRelative() is true. If the QFileInfo is empty it returns QDir::currentPath(). This function can be time consuming under Unix (in the order of milliseconds). \sa isRelative(), filePath()*/QStringQFileInfo::absoluteFilePath() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::AbsoluteName);}/*! 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 absoluteFilePath() returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalFilePath() returns an empty string. \sa filePath(), absoluteFilePath()*/QStringQFileInfo::canonicalFilePath() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::CanonicalName);}/*! Returns the file's path absolute path. This doesn't include the file name. \sa dir(), filePath(), fileName(), isRelative(), path()*/QStringQFileInfo::absolutePath() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::AbsolutePathName);}/*! 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. \sa absolutePath()*/QStringQFileInfo::canonicalPath() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::CanonicalPathName);}/*! Returns the file's path. This doesn't include the file name. \sa dir(), filePath(), fileName(), isRelative(), absolutePath()*/QStringQFileInfo::path() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::PathName);}/*! \fn bool QFileInfo::isAbsolute() const Returns true if the file path name is absolute, otherwise returns false if the path is relative. \sa isRelative()*//*! Returns true if the file path name is relative, otherwise returns false if the path is absolute (e.g. under Unix a path is absolute if it begins with a "/"). \sa isAbsolute()*/boolQFileInfo::isRelative() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return true; return d->data->fileEngine->isRelativePath();}/*! Converts the file's path to an absolute path if it is not already in that form. Returns true to indicate that the path was converted; otherwise returns false to indicate that the path was already absolute. \sa filePath(), isRelative()*/boolQFileInfo::makeAbsolute(){ Q_D(QFileInfo); if(!d->data->fileEngine || !d->data->fileEngine->isRelativePath()) return false; QString absFileName = d->getFileName(QAbstractFileEngine::AbsoluteName); d->initFileEngine(absFileName); return true;}/*! Returns true if the file exists; otherwise returns false.*/boolQFileInfo::exists() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return false; return d->getFileFlags(QAbstractFileEngine::ExistsFlag);}/*! Refreshes the information about the file, i.e. reads in information from the file system the next time a cached property is fetched.*/voidQFileInfo::refresh(){ Q_D(QFileInfo); d->reset();}/*! Returns the file name, including the path (which may be absolute or relative). \sa isRelative(), absoluteFilePath()*/QStringQFileInfo::filePath() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::DefaultName);}/*! Returns the name of the file, excluding the path. Example: \code QFileInfo fi("/tmp/archive.tar.gz"); QString name = fi.fileName(); // name = "archive.tar.gz" \endcode \sa isRelative(), filePath(), baseName(), extension()*/QStringQFileInfo::fileName() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::BaseName);}/*! Returns the base name of the file without the path. The base name consists of all characters in the file up to (but not including) the \e first '.' character. Example: \code QFileInfo fi("/tmp/archive.tar.gz"); QString base = fi.baseName(); // base = "archive" \endcode The base name of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc"). \sa fileName(), suffix(), completeSuffix(), completeBaseName()*/QStringQFileInfo::baseName() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); return d->getFileName(QAbstractFileEngine::BaseName).section(QLatin1Char('.'), 0, 0);}/*! Returns the complete base name of the file without the path. The complete base name consists of all characters in the file up to (but not including) the \e last '.' character. Example: \code QFileInfo fi("/tmp/archive.tar.gz"); QString base = fi.completeBaseName(); // base = "archive.tar" \endcode \sa fileName(), suffix(), completeSuffix(), baseName()*/QStringQFileInfo::completeBaseName() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); QString name = d->getFileName(QAbstractFileEngine::BaseName); int index = name.lastIndexOf(QLatin1Char('.')); return (index == -1) ? name : name.left(index);}/*! Returns the complete suffix of the file. The complete suffix consists of all characters in the file after (but not including) the first '.'. Example: \code QFileInfo fi("/tmp/archive.tar.gz"); QString ext = fi.completeSuffix(); // ext = "tar.gz" \endcode \sa fileName(), suffix(), baseName(), completeBaseName()*/QStringQFileInfo::completeSuffix() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); QString fileName = d->getFileName(QAbstractFileEngine::BaseName); int firstDot = fileName.indexOf(QLatin1Char('.')); if (firstDot == -1) return QLatin1String(""); return fileName.mid(firstDot + 1);}/*! Returns the suffix of the file. The suffix consists of all characters in the file after (but not including) the last '.'. Example: \code QFileInfo fi("/tmp/archive.tar.gz"); QString ext = fi.suffix(); // ext = "gz" \endcode The suffix of a file is computed equally on all platforms, independent of file naming conventions (e.g., ".bashrc" on Unix has an empty base name, and the suffix is "bashrc"). \sa fileName(), completeSuffix(), baseName(), completeBaseName()*/QStringQFileInfo::suffix() const{ Q_D(const QFileInfo); if(!d->data->fileEngine) return QLatin1String(""); QString fileName = d->getFileName(QAbstractFileEngine::BaseName); int lastDot = fileName.lastIndexOf(QLatin1Char('.')); if (lastDot == -1) return QLatin1String(""); return fileName.mid(lastDot + 1);}/*! Returns the path of the object's parent directory as a QDir object. \bold{Note:} The QDir returned always corresponds to the object's parent directory, even if the QFileInfo represents a directory. \sa dirPath(), filePath(), fileName(), isRelative(), absoluteDir()*/QDirQFileInfo::dir() const{ return QDir(path());}/*! Returns the file's absolute path as a QDir object. \sa filePath(), fileName(), isRelative(), dir()*/QDirQFileInfo::absoluteDir() const{ return QDir(absolutePath());}#ifdef QT3_SUPPORT/*! Use absoluteDir() or the dir() overload that takes no parameters instead.*/QDir QFileInfo::dir(bool absPath) const
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -