?? qfile.cpp
字號:
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); if (mode & Append) { seek(size()); } else { long pos = ftell(fh); if (pos != -1) seek(pos); } 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); if (mode & Append) seek(size()); 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) 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 the \a permissions specified. Returns true if successful, or false if the permissions cannot be modified. \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. Returns true if successful; otherwise returns false.*/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{ return QIODevice::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() || (isSequential() && bytesAvailable() == 0);}/*! \reimp*/bool QFile::seek(qint64 off){ Q_D(QFile); if (!isOpen()) { qWarning("QFile::seek: IODevice is not open"); return false; } if (!fileEngine()->seek(off) || !QIODevice::seek(off)) { QFile::FileError err = fileEngine()->error(); if(err == QFile::UnspecifiedError) err = QFile::PositionError; d->setError(err, fileEngine()->errorString()); return false; } d->error = NoError; 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); d->error = NoError; 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); d->error = NoError; QAbstractFileEngine *fe = d->fileEngine ? d->fileEngine : fileEngine(); qint64 ret = fe->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 + -