QFileDevice Class

The QFileDevice class provides an interface for reading from and writing to open files. More...

Header: #include <QFileDevice>
qmake: QT += core
Since: Qt 5.0
Inherits: QIODevice
Inherited By:

QFile and QSaveFile

This class was introduced in Qt 5.0.

Note: All functions in this class are reentrant.

Public Types

enum FileError { NoError, ReadError, WriteError, FatalError, ResourceError, …, CopyError }
enum FileHandleFlag { AutoCloseHandle, DontCloseHandle }
enum FileTime { FileAccessTime, FileBirthTime, FileMetadataChangeTime, FileModificationTime }
enum MemoryMapFlags { NoOptions, MapPrivateOption }
enum Permission { ReadOwner, WriteOwner, ExeOwner, ReadUser, WriteUser, …, ExeOther }

Detailed Description

QFileDevice is the base class for I/O devices that can read and write text and binary files and 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.

See also QFile and QTemporaryFile.

Member Type Documentation

enum QFileDevice::FileError

This enum describes the errors that may be returned by the error() function.

ConstantValueDescription
QFileDevice::NoError0No error occurred.
QFileDevice::ReadError1An error occurred when reading from the file.
QFileDevice::WriteError2An error occurred when writing to the file.
QFileDevice::FatalError3A fatal error occurred.
QFileDevice::ResourceError4Out of resources (e.g., too many open files, out of memory, etc.)
QFileDevice::OpenError5The file could not be opened.
QFileDevice::AbortError6The operation was aborted.
QFileDevice::TimeOutError7A timeout occurred.
QFileDevice::UnspecifiedError8An unspecified error occurred.
QFileDevice::RemoveError9The file could not be removed.
QFileDevice::RenameError10The file could not be renamed.
QFileDevice::PositionError11The position in the file could not be changed.
QFileDevice::ResizeError12The file could not be resized.
QFileDevice::PermissionsError13The file could not be accessed.
QFileDevice::CopyError14The file could not be copied.

enum QFileDevice::FileHandleFlag

This enum is used when opening a file to specify additional options which only apply to files and not to a generic QIODevice.

ConstantValueDescription
QFileDevice::AutoCloseHandle0x0001The 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.
QFileDevice::DontCloseHandle0If not explicitly closed, the underlying file handle is left open when the QFile object is destroyed.

enum QFileDevice::FileTime

This enum is used by the fileTime() and setFileTime() functions.

ConstantValueDescription
QFileDevice::FileAccessTime0When the file was most recently accessed (e.g. read or written to).
QFileDevice::FileBirthTime1When the file was created (may not be not supported on UNIX).
QFileDevice::FileMetadataChangeTime2When the file's metadata was last changed.
QFileDevice::FileModificationTime3When the file was most recently modified.

This enum was introduced or modified in Qt 5.10.

See also setFileTime(), fileTime(), and QFileInfo::fileTime().

enum QFileDevice::MemoryMapFlags

This enum describes special options that may be used by the map() function.

ConstantValueDescription
QFileDevice::NoOptions0No options.
QFileDevice::MapPrivateOption0x0001The 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.

This enum was introduced or modified in Qt 4.4.

enum QFileDevice::Permission

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.

ConstantValueDescription
QFileDevice::ReadOwner0x4000The file is readable by the owner of the file.
QFileDevice::WriteOwner0x2000The file is writable by the owner of the file.
QFileDevice::ExeOwner0x1000The file is executable by the owner of the file.
QFileDevice::ReadUser0x0400The file is readable by the user.
QFileDevice::WriteUser0x0200The file is writable by the user.
QFileDevice::ExeUser0x0100The file is executable by the user.
QFileDevice::ReadGroup0x0040The file is readable by the group.
QFileDevice::WriteGroup0x0020The file is writable by the group.
QFileDevice::ExeGroup0x0010The file is executable by the group.
QFileDevice::ReadOther0x0004The file is readable by anyone.
QFileDevice::WriteOther0x0002The file is writable by anyone.
QFileDevice::ExeOther0x0001The file is executable by anyone.

Warning: Because of differences in the platforms supported by Qt, the semantics of ReadUser, WriteUser and ExeUser are platform-dependent: On Unix, the rights of the owner of the file are returned and on Windows the rights of the current user are returned. This behavior might change in a future Qt version.

Note: On NTFS file systems, ownership and permissions checking is disabled by default for performance reasons. To enable it, include the following line:

 extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

Permission checking is then turned on and off by incrementing and decrementing qt_ntfs_permission_lookup by 1.

 qt_ntfs_permission_lookup++; // turn checking on
 qt_ntfs_permission_lookup--; // turn it off again