Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QFileDevice Class Reference

\inmodule QtCore More...

#include <qfiledevice.h>

+ Inheritance diagram for QFileDevice:
+ Collaboration diagram for QFileDevice:

Public Types

enum  FileError {
  NoError = 0 , ReadError = 1 , WriteError = 2 , FatalError = 3 ,
  ResourceError = 4 , OpenError = 5 , AbortError = 6 , TimeOutError = 7 ,
  UnspecifiedError = 8 , RemoveError = 9 , RenameError = 10 , PositionError = 11 ,
  ResizeError = 12 , PermissionsError = 13 , CopyError = 14
}
 This enum describes the errors that may be returned by the error() function. More...
 
enum  FileTime { FileAccessTime , FileBirthTime , FileMetadataChangeTime , FileModificationTime }
 
enum  Permission {
  ReadOwner = 0x4000 , WriteOwner = 0x2000 , ExeOwner = 0x1000 , ReadUser = 0x0400 ,
  WriteUser = 0x0200 , ExeUser = 0x0100 , ReadGroup = 0x0040 , WriteGroup = 0x0020 ,
  ExeGroup = 0x0010 , ReadOther = 0x0004 , WriteOther = 0x0002 , ExeOther = 0x0001
}
 This enum is used by the permission() function to report the permissions and ownership of a file. More...
 
enum  FileHandleFlag { AutoCloseHandle = 0x0001 , DontCloseHandle = 0 }
 This enum is used when opening a file to specify additional options which only apply to files and not to a generic QIODevice. More...
 
enum  MemoryMapFlag { NoOptions = 0 , MapPrivateOption = 0x0001 }
 
- Public Types inherited from QIODeviceBase
enum  OpenModeFlag {
  NotOpen = 0x0000 , ReadOnly = 0x0001 , WriteOnly = 0x0002 , ReadWrite = ReadOnly | WriteOnly ,
  Append = 0x0004 , Truncate = 0x0008 , Text = 0x0010 , Unbuffered = 0x0020 ,
  NewOnly = 0x0040 , ExistingOnly = 0x0080
}
 This enum is used with QIODevice::open() to describe the mode in which a device is opened. More...
 

Public Member Functions

 ~QFileDevice ()
 Destroys the file device, closing it if necessary.
 
FileError error () const
 Returns the file error status.
 
void unsetError ()
 Sets the file's error to QFileDevice::NoError.
 
void close () override
 Calls QFileDevice::flush() and closes the file.
 
bool isSequential () const override
 Returns true if the file can only be manipulated sequentially; otherwise returns false.
 
int handle () const
 Returns the file handle of the file.
 
virtual QString fileName () const
 Returns the name of the file.
 
qint64 pos () const override
 \reimp
 
bool seek (qint64 offset) override
 For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred.
 
bool atEnd () const override
 Returns true if the end of the file has been reached; otherwise returns false.
 
bool flush ()
 Flushes any buffered data to the file.
 
qint64 size () const override
 Returns the size of the file.
 
virtual bool resize (qint64 sz)
 Sets the file size (in bytes) sz.
 
virtual Permissions permissions () const
 Returns the complete OR-ed together combination of QFile::Permission for the file.
 
virtual bool setPermissions (Permissions permissionSpec)
 Sets the permissions for the file to the permissions specified.
 
ucharmap (qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions)
 Maps size bytes of the file into memory starting at offset.
 
bool unmap (uchar *address)
 Unmaps the memory address.
 
QDateTime fileTime (QFileDevice::FileTime time) const
 
bool setFileTime (const QDateTime &newDate, QFileDevice::FileTime fileTime)
 
- Public Member Functions inherited from QIODevice
 QIODevice ()
 Constructs a QIODevice object.
 
 QIODevice (QObject *parent)
 Constructs a QIODevice object with the given parent.
 
virtual ~QIODevice ()
 The destructor is virtual, and QIODevice is an abstract base class.
 
QIODeviceBase::OpenMode openMode () const
 Returns the mode in which the device has been opened; i.e.
 
void setTextModeEnabled (bool enabled)
 If enabled is true, this function sets the \l Text flag on the device; otherwise the \l Text flag is removed.
 
bool isTextModeEnabled () const
 Returns true if the \l Text flag is enabled; otherwise returns false.
 
bool isOpen () const
 Returns true if the device is open; otherwise returns false.
 
bool isReadable () const
 Returns true if data can be read from the device; otherwise returns false.
 
bool isWritable () const
 Returns true if data can be written to the device; otherwise returns false.
 
int readChannelCount () const
 
int writeChannelCount () const
 
int currentReadChannel () const
 
void setCurrentReadChannel (int channel)
 
int currentWriteChannel () const
 
void setCurrentWriteChannel (int channel)
 
virtual bool open (QIODeviceBase::OpenMode mode)
 Opens the device and sets its OpenMode to mode.
 
virtual bool reset ()
 Seeks to the start of input for random-access devices.
 
virtual qint64 bytesAvailable () const
 Returns the number of bytes that are available for reading.
 
virtual qint64 bytesToWrite () const
 For buffered devices, this function returns the number of bytes waiting to be written.
 
qint64 read (char *data, qint64 maxlen)
 Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
 
QByteArray read (qint64 maxlen)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads at most maxSize bytes from the device, and returns the data read as a QByteArray.
 
QByteArray readAll ()
 Reads all remaining data from the device, and returns it as a byte array.
 
qint64 readLine (char *data, qint64 maxlen)
 This function reads a line of ASCII characters from the device, up to a maximum of maxSize - 1 bytes, stores the characters in data, and returns the number of bytes read.
 
QByteArray readLine (qint64 maxlen=0)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Reads a line from the device, but no more than maxSize characters, and returns the result as a byte array.
 
virtual bool canReadLine () const
 Returns true if a complete line of data can be read from the device; otherwise returns false.
 
void startTransaction ()
 
void commitTransaction ()
 
void rollbackTransaction ()
 
bool isTransactionStarted () const
 
qint64 write (const char *data, qint64 len)
 Writes at most maxSize bytes of data from data to the device.
 
qint64 write (const char *data)
 
qint64 write (const QByteArray &data)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Writes the content of data to the device.
 
qint64 peek (char *data, qint64 maxlen)
 
QByteArray peek (qint64 maxlen)
 
qint64 skip (qint64 maxSize)
 
virtual bool waitForReadyRead (int msecs)
 Blocks until new data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed.
 
virtual bool waitForBytesWritten (int msecs)
 For buffered devices, this function waits until a payload of buffered written data has been written to the device and the bytesWritten() signal has been emitted, or until msecs milliseconds have passed.
 
void ungetChar (char c)
 Puts the character c back into the device, and decrements the current position unless the position is 0.
 
bool putChar (char c)
 Writes the character c to the device.
 
bool getChar (char *c)
 Reads one character from the device and stores it in c.
 
QString errorString () const
 Returns a human-readable description of the last device error that occurred.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Protected Member Functions

 QFileDevice ()
 \macro QT_USE_NODISCARD_FILE_OPEN \macro QT_NO_USE_NODISCARD_FILE_OPEN
 
 QFileDevice (QObject *parent)
 
 QFileDevice (QFileDevicePrivate &dd, QObject *parent=nullptr)
 
qint64 readData (char *data, qint64 maxlen) override
 \reimp
 
qint64 writeData (const char *data, qint64 len) override
 \reimp
 
qint64 readLineData (char *data, qint64 maxlen) override
 \reimp
 
- Protected Member Functions inherited from QIODevice
 QIODevice (QIODevicePrivate &dd, QObject *parent=nullptr)
 
virtual qint64 skipData (qint64 maxSize)
 
void setOpenMode (QIODeviceBase::OpenMode openMode)
 Sets the OpenMode of the device to openMode.
 
void setErrorString (const QString &errorString)
 Sets the human readable description of the last device error that occurred to str.
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QIODeviceBase
 ~QIODeviceBase ()=default
 

Related Symbols

(Note that these are not member symbols.)

 QFileDevice ()
 \macro QT_USE_NODISCARD_FILE_OPEN \macro QT_NO_USE_NODISCARD_FILE_OPEN
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- Signals inherited from QIODevice
void readyRead ()
 This signal is emitted once every time new data is available for reading from the device's current read channel.
 
void channelReadyRead (int channel)
 
void bytesWritten (qint64 bytes)
 This signal is emitted every time a payload of data has been written to the device's current write channel.
 
void channelBytesWritten (int channel, qint64 bytes)
 
void aboutToClose ()
 This signal is emitted when the device is about to close.
 
void readChannelFinished ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

\inmodule QtCore

Since
5.0

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

\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 QSaveFile, by providing all the operations that can be done on files that have been opened by QFile or QSaveFile.

See also
QFile, QSaveFile

Definition at line 31 of file qfiledevice.h.

Member Enumeration Documentation

◆ FileError

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 39 of file qfiledevice.h.

◆ FileHandleFlag

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 72 of file qfiledevice.h.

◆ FileTime

Since
5.10

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.

See also
setFileTime(), fileTime(), QFileInfo::fileTime()
Enumerator
FileAccessTime 
FileBirthTime 
FileMetadataChangeTime 
FileModificationTime 

Definition at line 57 of file qfiledevice.h.

◆ MemoryMapFlag

Since
4.4

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 101 of file qfiledevice.h.

◆ 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.

\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 others. \value WriteOther The file is writable by others. \value ExeOther The file is executable by others.

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:

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
Note
Since this is a non-atomic global variable, it is only safe to increment or decrement qt_ntfs_permission_lookup before any threads other than the main thread have started or after every thread other than the main thread has ended.
From Qt 6.6 the variable qt_ntfs_permission_lookup is deprecated. Please use the following alternatives.

The safe and easy way to manage permission checks is to use the RAII class QNtfsPermissionCheckGuard.

{
QNtfsPermissionCheckGuard permissionGuard; // check is enabled
// do complex things here that need permission check enabled
} // as the guard goes out of scope the check is disabled

If you need more fine-grained control, it is possible to manage the permission with the following functions instead:

qEnableNtfsPermissionChecks(); // turn checking on
qDisableNtfsPermissionChecks(); // turn it off again
The QNtfsPermissionCheckGuard class is a RAII class to manage NTFS permission checking.
qAreNtfsPermissionChecksEnabled()
[raii]
Q_CORE_EXPORT int qt_ntfs_permission_lookup
[0]
Definition ntfsp.cpp:10
void complexFunction()
[1]
Definition ntfsp.cpp:15
qEnableNtfsPermissionChecks()
qDisableNtfsPermissionChecks()
Enumerator
ReadOwner 
WriteOwner 
ExeOwner 
ReadUser 
WriteUser 
ExeUser 
ReadGroup 
WriteGroup 
ExeGroup 
ReadOther 
WriteOther 
ExeOther 

Definition at line 64 of file qfiledevice.h.

Constructor & Destructor Documentation

◆ ~QFileDevice()

QFileDevice::~QFileDevice ( )

Destroys the file device, closing it if necessary.

Definition at line 236 of file qfiledevice.cpp.

References close().

+ Here is the call graph for this function:

◆ QFileDevice() [1/3]

QFileDevice ( )
protected

\macro QT_USE_NODISCARD_FILE_OPEN \macro QT_NO_USE_NODISCARD_FILE_OPEN

Since
6.8

File-related I/O classes (such as QFile, QSaveFile, QTemporaryFile) have an {open()} method to open the file they act upon. It is important to check the return value of the call to {open()} before proceeding with reading or writing data into the file.

For this reason, starting with Qt 6.8, some overloads of {open()} have been marked with the {[[nodiscard]]} attribute. Since this change may raise warnings in existing codebases, user code can opt-in or opt-out from having the attribute applied by defining certain macros:

\list

  • If the {QT_USE_NODISCARD_FILE_OPEN} macro is defined, overloads of {open()} are marked as {[[nodiscard]]}.
  • If the {QT_NO_USE_NODISCARD_FILE_OPEN} is defined, the overloads of {open()} are {not} marked as {[[nodiscard]]}.
  • If neither macro is defined, then the default up to and including Qt 6.9 is not to have the attribute. Starting from Qt 6.10, the attribute is automatically applied.
  • If both macros are defined, the program is ill-formed. \endlist

Definition at line 213 of file qfiledevice.cpp.

◆ QFileDevice() [2/3]

QFileDevice::QFileDevice ( QObject * parent)
explicitprotected

Definition at line 220 of file qfiledevice.cpp.

◆ QFileDevice() [3/3]

QFileDevice::QFileDevice ( QFileDevicePrivate & dd,
QObject * parent = nullptr )
protected

Definition at line 227 of file qfiledevice.cpp.

Member Function Documentation

◆ atEnd()

bool QFileDevice::atEnd ( ) const
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 365 of file qfiledevice.cpp.

References QAbstractFileEngine::AtEndExtension, QIODevice::bytesAvailable(), d, QIODevice::isOpen(), and pos().

Referenced by QFile::copy(), QIBusPlatformInputContextPrivate::createConnection(), QBenchmarkValgrindUtils::extractResult(), getLibraryProjectsInOutputFolder(), QGeoFileTileCache::loadTiles(), lookupVendorIdInSystemDatabase(), noStream_snippet(), quick_test_main_with_setup(), QNetworkAccessFileBackend::read(), and QQmlJS::Dom::FileWriter::write().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ close()

void QFileDevice::close ( )
overridevirtual

Calls QFileDevice::flush() and closes the file.

Errors from flush are ignored.

See also
QIODevice::close()

Reimplemented from QIODevice.

Definition at line 326 of file qfiledevice.cpp.

References QIODevice::close(), d, flush(), QIODevice::isOpen(), and unsetError().

Referenced by ~QFileDevice(), QGeoFileTileCache::~QGeoFileTileCache(), QGeoFileTileCache::addToDiskCache(), QNetworkAccessFileBackend::close(), QNetworkFile::close(), QTlsPrivate::TlsCryptographOpenSSL::continueHandshake(), QFile::copy(), QNetworkDiskCache::data(), QTranslatorPrivate::do_load(), FileContent(), QNetworkDiskCache::fileMetaData(), QGeoFileTileCache::getFromDisk(), QGeoFileTileCacheOsm::getFromOfflineStorage(), QQmlJSLinter::lintFile(), QGeoFileTileCache::loadTiles(), mergeGradleProperties(), QFile::moveToTrash(), MainWindow::openFile(), QQmlJSTypeReader::operator()(), QSSGQmlUtilities::outputTextureAsset(), parseMountInfo(), patchQtCore(), printError(), quick_test_main_with_setup(), QCacheUtils::readCookedMesh(), readGradleProperties(), QMimeBinaryProvider::CacheFile::reload(), QFile::remove(), QFile::rename(), QGtk3Json::save(), QFile::setFileName(), AudioOutputExample::stopAudioOutput(), AudioInputExample::stopRecording(), dom::DataTransfer::toMimeDataWithFile(), updateFile(), QNetworkAccessFileBackend::uploadReadyReadSlot(), QQmlJS::Dom::FileWriter::write(), QSSGQmlUtilities::writeQmlForAnimation(), and QQuickTextDocumentPrivate::writeTo().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ error()

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.

See also
unsetError()

Definition at line 586 of file qfiledevice.cpp.

References d.

Referenced by QNetworkReplyFileImpl::QNetworkReplyFileImpl(), QFile::copy(), QImageReaderPrivate::initHandler(), QQmlJSLinter::lintFile(), QFile::moveToTrash(), QNetworkFile::open(), QNetworkAccessFileBackend::read(), QFile::remove(), and QFile::rename().

+ Here is the caller graph for this function:

◆ fileName()

QString QFileDevice::fileName ( ) const
virtual

Returns the name of the file.

The default implementation in QFileDevice returns a null string.

Reimplemented in QFile.

Definition at line 280 of file qfiledevice.cpp.

◆ fileTime()

QDateTime QFileDevice::fileTime ( QFileDevice::FileTime time) const
Since
5.10 Returns the file time specified by time. If the time cannot be determined return QDateTime() (an invalid date time).
See also
setFileTime(), FileTime, QDateTime::isValid()

Definition at line 774 of file qfiledevice.cpp.

References d, and time.

Referenced by setFileTime().

+ Here is the caller graph for this function:

◆ flush()

bool QFileDevice::flush ( )

Flushes any buffered data to the file.

Returns true if successful; otherwise returns false.

Definition at line 289 of file qfiledevice.cpp.

References d, qWarning, UnspecifiedError, and WriteError.

Referenced by close(), QFileDevicePrivate::ensureFlushed(), QTextStreamPrivate::flushWriteBuffer(), QQmlDocumentFormatting::process(), QNetworkAccessFileBackend::uploadReadyReadSlot(), QImageWriter::write(), QQmlJS::Dom::FileWriter::write(), and writeData().

+ Here is the caller graph for this function:

◆ handle()

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.

See also
QSocketNotifier

Definition at line 267 of file qfiledevice.cpp.

References d, and QIODevice::isOpen().

Referenced by QTranslatorPrivate::do_load(), QTextStreamPrivate::fillReadBuffer(), and Decoder::setSource().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isSequential()

bool QFileDevice::isSequential ( ) const
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.

See also
QIODevice::isSequential()

Reimplemented from QIODevice.

Definition at line 249 of file qfiledevice.cpp.

References d.

Referenced by QNetworkAccessFileBackend::open(), QFile::open(), QFile::open(), QNetworkAccessFileBackend::read(), and QFile::rename().

+ Here is the caller graph for this function:

◆ map()

uchar * QFileDevice::map ( qint64 offset,
qint64 size,
MemoryMapFlags flags = NoOptions )

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.

See also
unmap()

Definition at line 714 of file qfiledevice.cpp.

References d, QAbstractFileEngine::MapExtension, and unsetError().

Referenced by QIconCacheGtkReader::QIconCacheGtkReader(), findPatternUnloaded(), QMimeBinaryProvider::CacheFile::load(), qtiffMapProc(), QCacheUtils::readCookedMesh(), and readOrMapFile().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ permissions()

QFile::Permissions QFileDevice::permissions ( ) const
virtual

Returns the complete OR-ed together combination of QFile::Permission for the file.

See also
setPermissions()

Reimplemented in QFile.

Definition at line 653 of file qfiledevice.cpp.

References d, and QAbstractFileEngine::PermsMask.

Referenced by QFile::permissions(), and setPermissions().

+ Here is the caller graph for this function:

◆ pos()

qint64 QFileDevice::pos ( ) const
overridevirtual

\reimp

Reimplemented from QIODevice.

Definition at line 351 of file qfiledevice.cpp.

References QIODevice::pos().

Referenced by atEnd(), QFile::open(), QFile::open(), ResourceIOStream::Seek(), and ResourceIOStream::Tell().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readData()

qint64 QFileDevice::readData ( char * data,
qint64 maxlen )
overrideprotectedvirtual

\reimp

Implements QIODevice.

Definition at line 461 of file qfiledevice.cpp.

References d, QIODevice::read(), ReadError, unsetError(), and UnspecifiedError.

+ Here is the call graph for this function:

◆ readLineData()

qint64 QFileDevice::readLineData ( char * data,
qint64 maxlen )
overrideprotectedvirtual

\reimp

Reimplemented from QIODevice.

Definition at line 435 of file qfiledevice.cpp.

References d, QAbstractFileEngine::FastReadLineExtension, QIODevice::read(), and QIODevice::readLineData().

+ Here is the call graph for this function:

◆ resize()

bool QFileDevice::resize ( qint64 sz)
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.

Warning
This function can fail if the file doesn't exist.
See also
size()

Reimplemented in QFile.

Definition at line 629 of file qfiledevice.cpp.

References d, QIODevice::isOpen(), ResizeError, seek(), and unsetError().

Referenced by QFile::resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ seek()

bool QFileDevice::seek ( qint64 pos)
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 410 of file qfiledevice.cpp.

References d, QIODevice::isOpen(), PositionError, qWarning, QIODevice::seek(), unsetError(), and UnspecifiedError.

Referenced by QTranslatorPrivate::do_load(), QFile::open(), resize(), ResourceIOStream::Seek(), and QTextOdfWriter::writeInlineCharacter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setFileTime()

bool QFileDevice::setFileTime ( const QDateTime & newDate,
QFileDevice::FileTime fileTime )
Since
5.10 Sets the file time specified by fileTime to newDate, returning true if successful; otherwise returns false.
Note
The file must be open to use this function.
See also
fileTime(), FileTime

Definition at line 793 of file qfiledevice.cpp.

References d, fileTime(), tr, unsetError(), and UnspecifiedError.

+ Here is the call graph for this function:

◆ setPermissions()

bool QFileDevice::setPermissions ( Permissions permissions)
virtual

Sets the permissions for the file to the permissions specified.

Returns true if successful, or false if the permissions cannot be modified.

Warning
This function does not manipulate ACLs, which may limit its effectiveness.
See also
permissions()

Reimplemented in QFile.

Definition at line 670 of file qfiledevice.cpp.

References d, permissions(), PermissionsError, and unsetError().

Referenced by QFile::setPermissions().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ size()

qint64 QFileDevice::size ( ) const
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 610 of file qfiledevice.cpp.

References d.

Referenced by QFile::size().

+ Here is the caller graph for this function:

◆ unmap()

bool QFileDevice::unmap ( uchar * address)

Unmaps the memory address.

Returns true if the unmap succeeds; false otherwise.

See also
map()

Definition at line 735 of file qfiledevice.cpp.

References d, PermissionsError, tr, QAbstractFileEngine::UnMapExtension, and unsetError().

Referenced by qtiffUnmapProc(), and QCacheUtils::readCookedMesh().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ unsetError()

void QFileDevice::unsetError ( )

Sets the file's error to QFileDevice::NoError.

See also
error()

Definition at line 597 of file qfiledevice.cpp.

References d, and NoError.

Referenced by close(), QFile::copy(), QFile::link(), map(), QFile::moveToTrash(), QFile::open(), QFile::open(), QFile::open(), readData(), QFile::remove(), QFile::rename(), resize(), seek(), setFileTime(), setPermissions(), unmap(), and writeData().

+ Here is the caller graph for this function:

◆ writeData()

qint64 QFileDevice::writeData ( const char * data,
qint64 len )
overrideprotectedvirtual

\reimp

Implements QIODevice.

Definition at line 546 of file qfiledevice.cpp.

References d, flush(), ret, QIODeviceBase::Unbuffered, unsetError(), UnspecifiedError, and WriteError.

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QFileDevice()

QFileDevice ( )
related

\macro QT_USE_NODISCARD_FILE_OPEN \macro QT_NO_USE_NODISCARD_FILE_OPEN

Since
6.8

File-related I/O classes (such as QFile, QSaveFile, QTemporaryFile) have an {open()} method to open the file they act upon. It is important to check the return value of the call to {open()} before proceeding with reading or writing data into the file.

For this reason, starting with Qt 6.8, some overloads of {open()} have been marked with the {[[nodiscard]]} attribute. Since this change may raise warnings in existing codebases, user code can opt-in or opt-out from having the attribute applied by defining certain macros:

\list

  • If the {QT_USE_NODISCARD_FILE_OPEN} macro is defined, overloads of {open()} are marked as {[[nodiscard]]}.
  • If the {QT_NO_USE_NODISCARD_FILE_OPEN} is defined, the overloads of {open()} are {not} marked as {[[nodiscard]]}.
  • If neither macro is defined, then the default up to and including Qt 6.9 is not to have the attribute. Starting from Qt 6.10, the attribute is automatically applied.
  • If both macros are defined, the program is ill-formed. \endlist

Definition at line 213 of file qfiledevice.cpp.


The documentation for this class was generated from the following files: