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

📄 qfile.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        QByteArray myEncoderFunc(const QString &fileName);    \endcode    \sa setEncodingFunction(), encodeName()*//*!    This does the reverse of QFile::encodeName() using \a localFileName.    \sa setDecodingFunction(), encodeName()*/QStringQFile::decodeName(const QByteArray &localFileName){    return (*QFilePrivate::decoder)(localFileName);}/*!    \fn void QFile::setEncodingFunction(EncoderFn function)    \nonreentrant    Sets the \a function for encoding Unicode file names. The    default encodes in the locale-specific 8-bit encoding.    \sa encodeName(), setDecodingFunction()*/voidQFile::setEncodingFunction(EncoderFn f){    if (!f)        f = locale_encode;    QFilePrivate::encoder = f;}/*!    \typedef QFile::DecoderFn    This is a typedef for a pointer to a function with the following    signature:    \code        QString myDecoderFunc(const QByteArray &localFileName);    \endcode    \sa setDecodingFunction()*//*!    \fn void QFile::setDecodingFunction(DecoderFn function)    \nonreentrant    Sets the \a function for decoding 8-bit file names. The    default uses the locale-specific 8-bit encoding.    \sa setEncodingFunction(), decodeName()*/voidQFile::setDecodingFunction(DecoderFn f){    if (!f)        f = locale_decode;    QFilePrivate::decoder = f;}/*!    \overload    Returns true if the file specified by fileName() exists; otherwise    returns false.    \sa fileName(), setFileName()*/boolQFile::exists() const{    // 0x1000000 = QAbstractFileEngine::Refresh, forcing an update    return (fileEngine()->fileFlags(QAbstractFileEngine::FlagsMask                                    | QAbstractFileEngine::FileFlag(0x1000000)) & QAbstractFileEngine::ExistsFlag);}/*!    Returns true if the file specified by \a fileName exists; otherwise    returns false.*/boolQFile::exists(const QString &fileName){    return QFileInfo(fileName).exists();}/*!    \overload    Returns the absolute path of the file or directory a symlink (or shortcut    on Windows) points to, or a an empty string if the object isn't a symbolic    link.    This name may not represent an existing file; it is only a string.    QFile::exists() returns true if the symlink points to an existing file.    \sa fileName() setFileName()*/QStringQFile::readLink() const{    return fileEngine()->fileName(QAbstractFileEngine::LinkName);}/*!    Returns the absolute path of the file or directory referred to by the    symlink (or shortcut on Windows) specified by \a fileName, or returns an    empty string if the \a fileName does not correspond to a symbolic link.    This name may not represent an existing file; it is only a string.    QFile::exists() returns true if the symlink points to an existing file.*/QStringQFile::readLink(const QString &fileName){    return QFileInfo(fileName).readLink();}/*!    Removes the file specified by fileName(). Returns true if successful;    otherwise returns false.    The file is closed before it is removed.    \sa setFileName()*/boolQFile::remove(){    Q_D(QFile);    if (d->fileName.isEmpty()) {        qWarning("QFile::remove: Empty or null file name");        return false;    }    close();    if(error() == QFile::NoError) {        if(fileEngine()->remove()) {            unsetError();            return true;        }        d->setError(QFile::RemoveError, errno);    }    return false;}/*!    \overload    Removes the file specified by the \a fileName given.    Returns true if successful; otherwise returns false.    \sa remove()*/boolQFile::remove(const QString &fileName){    return QFile(fileName).remove();}/*!    Renames the file currently specified by fileName() to \a newName.    Returns true if successful; otherwise returns false.    If a file with the name \a newName already exists, rename() returns false    (i.e., QFile will not overwrite it).    The file is closed before it is renamed.    \sa setFileName()*/boolQFile::rename(const QString &newName){    Q_D(QFile);    if (d->fileName.isEmpty()) {        qWarning("QFile::rename: Empty or null file name");        return false;    }    if (QFile(newName).exists()) {        // ### Race condition. If a file is moved in after this, it /will/ be        // overwritten. On Unix, the proper solution is to use hardlinks:        // return ::link(old, new) && ::remove(old);        return false;    }    close();    if(error() == QFile::NoError) {        if (fileEngine()->rename(newName)) {            unsetError();            return true;        }        QFile in(fileName());        QFile out(newName);        if (in.open(QIODevice::ReadOnly)) {            if(out.open(QIODevice::WriteOnly | QIODevice::Truncate)) {                bool error = false;                char block[1024];                while (!in.atEnd()) {                    qint64 read = in.read(block, 1024);                    if (read == -1) {                        error = true;                        break;                    }                    if (read != out.write(block, read)) {                        d->setError(QFile::CopyError, QLatin1String("Failure to write block"));                        error = true;                        break;                    }                }                if(!error)                    in.remove();                return !error;            }        }        d->setError(QFile::RenameError, errno);    }    return false;}/*!    \overload    Renames the file \a oldName to \a newName. Returns true if    successful; otherwise returns false.    If a file with the name \a newName already exists, rename() returns false    (i.e., QFile will not overwrite it).    \sa rename()*/boolQFile::rename(const QString &oldName, const QString &newName){    return QFile(oldName).rename(newName);}/*!    Creates a link named \a linkName that points to the file currently specified by fileName().    What a link is depends on the underlying filesystem    (be it a shortcut on Windows or a symbolic link on Unix). Returns    true if successful; otherwise returns false.    \sa setFileName()*/boolQFile::link(const QString &linkName){    Q_D(QFile);    if (d->fileName.isEmpty()) {        qWarning("QFile::link: Empty or null file name");        return false;    }    QFileInfo fi(linkName);    if(fileEngine()->link(fi.absoluteFilePath())) {        unsetError();        return true;    }    d->setError(QFile::RenameError, errno);    return false;}/*!    \overload    Creates a link named \a linkName that points to the file \a fileName. What a link is    depends on the underlying filesystem (be it a shortcut on Windows    or a symbolic link on Unix). Returns true if successful; otherwise    returns false.    \sa link()*/boolQFile::link(const QString &fileName, const QString &linkName){    return QFile(fileName).link(linkName);}/*!    Copies the file currently specified by fileName() to a file called    \a newName.  Returns true if successful; otherwise returns false.    Note that if a file with the name \a newName already exists,    copy() returns false (i.e. QFile will not overwrite it).    The source file is closed before it is copied, and the new file's    timestamp will be the time of the copy operation.    \sa setFileName()*/boolQFile::copy(const QString &newName){    Q_D(QFile);    if (d->fileName.isEmpty()) {        qWarning("QFile::copy: Empty or null file name");        return false;    }    close();    if(error() == QFile::NoError) {        if(fileEngine()->copy(newName)) {            unsetError();            return true;        } else {            bool error = false;            if(!open(QFile::ReadOnly)) {                error = true;                QString errorMessage = QLatin1String("Cannot open %1 for input");                d->setError(QFile::CopyError, errorMessage.arg(d->fileName));            } else {                QTemporaryFile out;                if(!out.open()) {                    close();                    error = true;                    d->setError(QFile::CopyError, QLatin1String("Cannot open for output"));                } else {                    char block[1024];                    while(!atEnd()) {                        qint64 in = read(block, 1024);                        if(in == -1)                            break;                        if(in != out.write(block, in)) {                            d->setError(QFile::CopyError, QLatin1String("Failure to write block"));                            error = true;                            break;                        }                    }                    if(!error && !out.rename(newName)) {                        error = true;                        QString errorMessage = QLatin1String("Cannot create %1 for output");                        d->setError(QFile::CopyError, errorMessage.arg(newName));                    }                }            }            if(!error) {                QFile::setPermissions(newName, permissions());                unsetError();                return true;            }        }    }    return false;}/*!    \overload    Copies the file \a fileName to \a newName. Returns true if successful;    otherwise returns false.    If a file with the name \a newName already exists, copy() returns false    (i.e., QFile will not overwrite it).    \sa rename()*/boolQFile::copy(const QString &fileName, const QString &newName){    return QFile(fileName).copy(newName);}/*!    Returns true if the file can only be manipulated sequentially;    otherwise returns false.    Most files support random-access, but some special files may not.    \sa QIODevice::isSequential()*/bool QFile::isSequential() const{    Q_D(const QFile);    return d->fileEngine && d->fileEngine->isSequential();}/*!    Opens the file using OpenMode \a mode.    The \a mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or    QIODevice::ReadWrite. It may also have additional flags, such as    QIODevice::Text and QIODevice::Unbuffered.    \sa QIODevice::OpenMode*/bool QFile::open(OpenMode mode){    Q_D(QFile);    if (isOpen()) {        qWarning("QFile::open: File already open");        return false;    }    if (mode & Append)        mode |= WriteOnly;    unsetError();    if ((mode & (ReadOnly | WriteOnly)) == 0) {        qWarning("QIODevice::open: File access not specified");        return false;    }    if (fileEngine()->open(mode)) {        setOpenMode(mode);        return true;    }    QFile::FileError err = fileEngine()->error();    if(err == QFile::UnspecifiedError)        err = QFile::OpenError;    d->setError(err, fileEngine()->errorString());    return false;

⌨️ 快捷键说明

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