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

📄 qfile.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
}/*! \fn QFile::open(OpenMode, FILE*)    Use open(FILE *, OpenMode) instead.*//*!    \overload    Opens the existing file handle \a fh in the given \a mode.    Returns true if successful; otherwise returns false.    Example:    \code        #include <stdio.h>        void printError(const char* msg)        {            QFile file;            file.open(stderr, QIODevice::WriteOnly);            file.write(msg, qstrlen(msg));        // write to stderr            file.close();        }    \endcode    When a QFile is opened using this function, close() does not actually    close the file, but only flushes it.    \warning If \a fh is \c stdin, \c stdout, or \c stderr, you may not be    able to seek(). See QIODevice::isSequentialAccess() for more    information.    \sa close()*/bool QFile::open(FILE *fh, 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("QFile::open: File access not specified");        return false;    }    if(d->openExternalFile(mode, fh)) {        setOpenMode(mode);        return true;    }    return false;}/*! \fn QFile::open(OpenMode, int)    Use open(int, OpenMode) instead.*//*!    \overload    Opens the existing file descripter \a fd in the given \a mode.    Returns true if successful; otherwise returns false.    When a QFile is opened using this function, close() does not    actually close the file.    The QFile that is opened using this function is automatically set    to be in raw mode; this means that the file input/output functions    are slow. If you run into performance issues, you should try to    use one of the other open functions.    \warning If \a fd is 0 (\c stdin), 1 (\c stdout), or 2 (\c    stderr), you may not be able to seek(). size() is set to \c    LLONG_MAX (in \c <climits>).    \sa close()*/bool QFile::open(int fd, 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("QFile::open: File access not specified");        return false;    }    if(d->openExternalFile(mode, fd)) {        setOpenMode(mode);        return true;    }    return false;}/*!  Returns the file handle of the file.  This is a small positive integer, suitable for use with C library  functions such as fdopen() and fcntl(). On systems that use file  descriptors for sockets (i.e. Unix systems, but not Windows) the handle  can be used with QSocketNotifier as well.  If the file is not open, or there is an error, handle() returns -1.  \sa QSocketNotifier*/intQFile::handle() const{    if (!isOpen())        return -1;    if (QAbstractFileEngine *engine = fileEngine())        return engine->handle();    return -1;}/*!    \fn QString QFile::name() const    Use fileName() instead.*//*!    \fn void QFile::setName(const QString &name)    Use setFileName() instead.*//*!    Sets the file size (in bytes) \a sz. Returns true if the file if the    resize succeeds; false otherwise. If \a sz is larger than the file    currently is the new bytes will be set to 0, if \a sz is smaller the    file is simply truncated.    \sa size(), setFileName()*/boolQFile::resize(qint64 sz){    Q_D(QFile);    if (isOpen() && fileEngine()->pos() > sz)        fileEngine()->seek(sz);    if(fileEngine()->setSize(sz)) {        unsetError();        return true;    }    d->setError(QFile::ResizeError, errno);    return false;}/*!    \overload    Sets \a fileName to size (in bytes) \a sz. Returns true if the file if    the resize succeeds; false otherwise. If \a sz is larger than \a    fileName currently is the new bytes will be set to 0, if \a sz is    smaller the file is simply truncated.    \sa resize()*/boolQFile::resize(const QString &fileName, qint64 sz){    return QFile(fileName).resize(sz);}/*!    Returns the complete OR-ed together combination of    QFile::Permission for the file.    \sa setPermissions(), setFileName()*/QFile::PermissionsQFile::permissions() const{    QAbstractFileEngine::FileFlags perms = fileEngine()->fileFlags(QAbstractFileEngine::PermsMask) & QAbstractFileEngine::PermsMask;    return QFile::Permissions((int)perms); //ewww}/*!    \overload    Returns the complete OR-ed together combination of    QFile::Permission for \a fileName.*/QFile::PermissionsQFile::permissions(const QString &fileName){    return QFile(fileName).permissions();}/*!    Sets the permissions for the file to \a permissions.    \sa permissions(), setFileName()*/boolQFile::setPermissions(Permissions permissions){    Q_D(QFile);    if(fileEngine()->setPermissions(permissions)) {        unsetError();        return true;    }    d->setError(QFile::PermissionsError, errno);    return false;}/*!    \overload    Sets the permissions for \a fileName file to \a permissions.*/boolQFile::setPermissions(const QString &fileName, Permissions permissions){    return QFile(fileName).setPermissions(permissions);}/*!    Flushes any buffered data to the file.*/boolQFile::flush(){    Q_D(QFile);    if (!fileEngine()->flush()) {        QFile::FileError err = fileEngine()->error();        if(err == QFile::UnspecifiedError)            err = QFile::WriteError;        d->setError(err, fileEngine()->errorString());        return false;    }    return true;}/*!  \reimp*/voidQFile::close(){    Q_D(QFile);    if(!isOpen())        return;    QIODevice::close();    unsetError();    if(!fileEngine()->close())        d->setError(fileEngine()->error(), fileEngine()->errorString());}/*!  Returns the size of the file.  For regular empty files on Unix (e.g. those in \c /proc), this function  returns 0; the contents of such a file are generated on demand in response  to you calling read().*/qint64 QFile::size() const{    return fileEngine()->size();}/*!  \reimp*/qint64 QFile::pos() const{    if (!isOpen())        return 0;    return fileEngine()->pos();}/*!  Returns true if the end of the file has been reached; otherwise returns  false.  For regular empty files on Unix (e.g. those in \c /proc), this function  returns true, since the file system reports that the size of such a file is  0. Therefore, you should not depend on atEnd() when reading data from such a  file, but rather call read() until no more data can be read.*/bool QFile::atEnd() const{    if (!isOpen())        return true;    return QIODevice::atEnd();}/*!  \reimp*/bool QFile::seek(qint64 off){    Q_D(QFile);    if (!isOpen()) {        qWarning("QFile::seek: IODevice is not open");        return false;    }    QIODevice::seek(off);    if(!fileEngine()->seek(off)) {        QFile::FileError err = fileEngine()->error();        if(err == QFile::UnspecifiedError)            err = QFile::PositionError;        d->setError(err, fileEngine()->errorString());        return false;    }    unsetError();    return true;}/*!  \reimp*/qint64 QFile::readLineData(char *data, qint64 maxlen){    return fileEngine()->readLine(data, maxlen);}/*!  \reimp*/qint64 QFile::readData(char *data, qint64 len){    Q_D(QFile);    unsetError();    qint64 ret = -1;    qint64 read = fileEngine()->read(data, len);    if (read != -1)        ret = read;    if(ret < 0) {        QFile::FileError err = fileEngine()->error();        if(err == QFile::UnspecifiedError)            err = QFile::ReadError;        d->setError(err, fileEngine()->errorString());    }    return ret;}/*!  \reimp*/qint64QFile::writeData(const char *data, qint64 len){    Q_D(QFile);    unsetError();    qint64 ret = fileEngine()->write(data, len);    if(ret < 0) {        QFile::FileError err = fileEngine()->error();        if(err == QFile::UnspecifiedError)            err = QFile::WriteError;        d->setError(err, fileEngine()->errorString());    }    return ret;}/*!    \internal    Returns the QIOEngine for this QFile object.*/QAbstractFileEngine *QFile::fileEngine() const{    Q_D(const QFile);    if(!d->fileEngine)        d->fileEngine = QAbstractFileEngine::create(d->fileName);    return d->fileEngine;}/*!    Returns the file error status.    The I/O device status returns an error code. For example, if open()    returns false, or a read/write operation returns -1, this function can    be called to find out the reason why the operation failed.    \sa unsetError()*/QFile::FileErrorQFile::error() const{    Q_D(const QFile);    return d->error;}/*!    Sets the file's error to QFile::NoError.    \sa error()*/voidQFile::unsetError(){    Q_D(QFile);    d->setError(QFile::NoError);}

⌨️ 快捷键说明

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