QtBase
v6.3.1
|
The QFileDevice class provides an interface for reading from and writing to open files. More...
#include <qfiledevice.h>
The QFileDevice class provides an interface for reading from and writing to open files.
\inmodule QtCore
\reentrant
QFileDevice is the base class for I/O devices that can read and write text and binary files and \l{The Qt Resource System}{resources}. QFile offers the main functionality, QFileDevice serves as a base class for sharing functionality with other file devices such as QTemporaryFile, by providing all the operations that can be done on files that have been opened by QFile or QTemporaryFile.
Definition at line 51 of file qfiledevice.h.
This enum describes the errors that may be returned by the error() function.
\value NoError No error occurred. \value ReadError An error occurred when reading from the file. \value WriteError An error occurred when writing to the file. \value FatalError A fatal error occurred. \value ResourceError Out of resources (e.g., too many open files, out of memory, etc.) \value OpenError The file could not be opened. \value AbortError The operation was aborted. \value TimeOutError A timeout occurred. \value UnspecifiedError An unspecified error occurred. \value RemoveError The file could not be removed. \value RenameError The file could not be renamed. \value PositionError The position in the file could not be changed. \value ResizeError The file could not be resized. \value PermissionsError The file could not be accessed. \value CopyError The file could not be copied.
Enumerator | |
---|---|
NoError | |
ReadError | |
WriteError | |
FatalError | |
ResourceError | |
OpenError | |
AbortError | |
TimeOutError | |
UnspecifiedError | |
RemoveError | |
RenameError | |
PositionError | |
ResizeError | |
PermissionsError | |
CopyError |
Definition at line 59 of file qfiledevice.h.
This enum is used when opening a file to specify additional options which only apply to files and not to a generic QIODevice.
\value AutoCloseHandle The file handle passed into open() should be closed by close(), the default behavior is that close just flushes the file and the application is responsible for closing the file handle. When opening a file by name, this flag is ignored as Qt always owns the file handle and must close it. \value DontCloseHandle If not explicitly closed, the underlying file handle is left open when the QFile object is destroyed.
Enumerator | |
---|---|
AutoCloseHandle | |
DontCloseHandle |
Definition at line 92 of file qfiledevice.h.
This enum is used by the fileTime() and setFileTime() functions.
\value FileAccessTime When the file was most recently accessed (e.g. read or written to). \value FileBirthTime When the file was created (may not be not supported on UNIX). \value FileMetadataChangeTime When the file's metadata was last changed. \value FileModificationTime When the file was most recently modified.
Enumerator | |
---|---|
FileAccessTime | |
FileBirthTime | |
FileMetadataChangeTime | |
FileModificationTime |
Definition at line 77 of file qfiledevice.h.
This enum describes special options that may be used by the map() function.
\value NoOptions No options. \value MapPrivateOption The mapped memory will be private, so any modifications will not be visible to other processes and will not be written to disk. Any such modifications will be lost when the memory is unmapped. It is unspecified whether modifications made to the file made after the mapping is created will be visible through the mapped memory. This enum value was introduced in Qt 5.4.
Enumerator | |
---|---|
NoOptions | |
MapPrivateOption |
Definition at line 121 of file qfiledevice.h.
This enum is used by the permission() function to report the permissions and ownership of a file. The values may be OR-ed together to test multiple permissions and ownership values.
\value ReadOwner The file is readable by the owner of the file. \value WriteOwner The file is writable by the owner of the file. \value ExeOwner The file is executable by the owner of the file. \value ReadUser The file is readable by the user. \value WriteUser The file is writable by the user. \value ExeUser The file is executable by the user. \value ReadGroup The file is readable by the group. \value WriteGroup The file is writable by the group. \value ExeGroup The file is executable by the group. \value ReadOther The file is readable by anyone. \value WriteOther The file is writable by anyone. \value ExeOther The file is executable by anyone.
Permission checking is then turned on and off by incrementing and decrementing qt_ntfs_permission_lookup
by 1.
Enumerator | |
---|---|
ReadOwner | |
WriteOwner | |
ExeOwner | |
ReadUser | |
WriteUser | |
ExeUser | |
ReadGroup | |
WriteGroup | |
ExeGroup | |
ReadOther | |
WriteOther | |
ExeOther |
Definition at line 84 of file qfiledevice.h.
QFileDevice::~QFileDevice | ( | ) |
Destroys the file device, closing it if necessary.
Definition at line 224 of file qfiledevice.cpp.
|
protected |
Definition at line 201 of file qfiledevice.cpp.
|
explicitprotected |
Definition at line 208 of file qfiledevice.cpp.
|
protected |
Definition at line 215 of file qfiledevice.cpp.
|
overridevirtual |
Returns true
if the end of the file has been reached; otherwise returns false.
For regular empty files on Unix (e.g. those in /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.
Reimplemented from QIODevice.
Definition at line 353 of file qfiledevice.cpp.
|
overridevirtual |
Calls QFileDevice::flush() and closes the file. Errors from flush are ignored.
Reimplemented from QIODevice.
Definition at line 314 of file qfiledevice.cpp.
QFileDevice::FileError QFileDevice::error | ( | ) | const |
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.
Definition at line 574 of file qfiledevice.cpp.
|
virtual |
Returns the name of the file. The default implementation in QFileDevice returns a null string.
Reimplemented in QTemporaryFile, QSaveFile, and QFile.
Definition at line 268 of file qfiledevice.cpp.
QDateTime QFileDevice::fileTime | ( | QFileDevice::FileTime | time | ) | const |
Definition at line 771 of file qfiledevice.cpp.
bool QFileDevice::flush | ( | ) |
Flushes any buffered data to the file. Returns true
if successful; otherwise returns false
.
Definition at line 277 of file qfiledevice.cpp.
int QFileDevice::handle | ( | ) | const |
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.
Definition at line 255 of file qfiledevice.cpp.
|
overridevirtual |
Returns true
if the file can only be manipulated sequentially; otherwise returns false
.
Most files support random-access, but some special files may not.
Reimplemented from QIODevice.
Reimplemented in QSequentialFile.
Definition at line 237 of file qfiledevice.cpp.
Maps size bytes of the file into memory starting at offset. A file should be open for a map to succeed but the file does not need to stay open after the memory has been mapped. When the QFile is destroyed or a new file is opened with this object, any maps that have not been unmapped will automatically be unmapped.
The mapping will have the same open mode as the file (read and/or write), except when using MapPrivateOption, in which case it is always possible to write to the mapped memory.
Any mapping options can be passed through flags.
Returns a pointer to the memory or \nullptr if there is an error.
Definition at line 702 of file qfiledevice.cpp.
|
virtual |
Returns the complete OR-ed together combination of QFile::Permission for the file.
Reimplemented in QFile.
Definition at line 641 of file qfiledevice.cpp.
|
overridevirtual |
\reimp
Reimplemented from QIODevice.
Definition at line 339 of file qfiledevice.cpp.
\reimp
Implements QIODevice.
Definition at line 449 of file qfiledevice.cpp.
\reimp
Reimplemented from QIODevice.
Definition at line 423 of file qfiledevice.cpp.
|
virtual |
Sets the file size (in bytes) sz. Returns true
if the resize succeeds; false otherwise. If sz is larger than the file currently is, the new bytes will be set to 0; if sz is smaller, the file is simply truncated.
Reimplemented in QFile.
Definition at line 617 of file qfiledevice.cpp.
|
overridevirtual |
For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred. For sequential devices, the default behavior is to do nothing and return false.
Seeking beyond the end of a file: If the position is beyond the end of a file, then seek() will not immediately extend the file. If a write is performed at this position, then the file will be extended. The content of the file between the previous end of file and the newly written data is UNDEFINED and varies between platforms and file systems.
Reimplemented from QIODevice.
Definition at line 398 of file qfiledevice.cpp.
bool QFileDevice::setFileTime | ( | const QDateTime & | newDate, |
QFileDevice::FileTime | fileTime | ||
) |
Definition at line 790 of file qfiledevice.cpp.
|
virtual |
Sets the permissions for the file to the permissions specified. Returns true
if successful, or false
if the permissions cannot be modified.
Reimplemented in QFile.
Definition at line 658 of file qfiledevice.cpp.
|
overridevirtual |
Returns the size of the file.
For regular empty files on Unix (e.g. those in /proc
), this function returns 0; the contents of such a file are generated on demand in response to you calling read().
Reimplemented from QIODevice.
Definition at line 598 of file qfiledevice.cpp.
bool QFileDevice::unmap | ( | uchar * | address | ) |
Unmaps the memory address.
Returns true
if the unmap succeeds; false otherwise.
Definition at line 723 of file qfiledevice.cpp.
void QFileDevice::unsetError | ( | ) |
Sets the file's error to QFileDevice::NoError.
Definition at line 585 of file qfiledevice.cpp.
\reimp
Implements QIODevice.
Reimplemented in QSaveFile.
Definition at line 534 of file qfiledevice.cpp.