Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
QFile Class Reference

\inmodule QtCore More...

#include <qfile.h>

+ Inheritance diagram for QFile:
+ Collaboration diagram for QFile:

Public Member Functions

 QFile ()
 Constructs a QFile object.
 
QFILE_MAYBE_EXPLICIT QFile (const QString &name)
 
 QFile (QObject *parent)
 Constructs a new file object with the given parent.
 
 QFile (const QString &name, QObject *parent)
 Constructs a new file object with the given parent to represent the file with the specified name.
 
 ~QFile ()
 Destroys the file object, closing it if necessary.
 
QString fileName () const override
 Returns the name set by setFileName() or to the QFile constructors.
 
void setFileName (const QString &name)
 Sets the name of the file.
 
bool exists () const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the file specified by fileName() exists; otherwise returns false.
 
QString symLinkTarget () const
 
bool remove ()
 Removes the file specified by fileName().
 
bool moveToTrash ()
 
bool rename (const QString &newName)
 Renames the file currently specified by fileName() to newName.
 
bool link (const QString &newName)
 Creates a link named linkName that points to the file currently specified by fileName().
 
bool copy (const QString &newName)
 Copies the file named fileName() to newName.
 
bool open (OpenMode flags) override
 Opens the file using OpenMode mode, returning true if successful; otherwise false.
 
bool open (OpenMode flags, Permissions permissions)
 
bool open (FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Opens the existing file handle fh in the given mode.
 
bool open (int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Opens the existing file descriptor fd in the given mode.
 
qint64 size () const override
 \reimp
 
bool resize (qint64 sz) override
 \reimp
 
Permissions permissions () const override
 \reimp
 
bool setPermissions (Permissions permissionSpec) override
 Sets the permissions for the file to the permissions specified.
 
- Public Member Functions inherited from QFileDevice
 ~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.
 
virtual bool isSequential () const
 Returns true if this device is sequential; 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 void close ()
 First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
 
virtual qint64 pos () const
 For random-access devices, this function returns the position that data is written to or read from.
 
virtual qint64 size () const
 For open random-access devices, this function returns the size of the device.
 
virtual bool seek (qint64 pos)
 For random-access devices, this function sets the current position to pos, returning true on success, or false if an error occurred.
 
virtual bool atEnd () const
 Returns true if the current read and write position is at the end of the device (i.e.
 
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.
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children.
 
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::milliseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
template<typename T >
findChild (const QString &aName=QString(), 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 (const QString &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 >
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.
 

Static Public Member Functions

static QByteArray encodeName (const QString &fileName)
 Converts fileName to an 8-bit encoding that you can use in native APIs.
 
static QString decodeName (const QByteArray &localFileName)
 This does the reverse of QFile::encodeName() using localFileName.
 
static QString decodeName (const char *localFileName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the Unicode version of the given localFileName.
 
static bool exists (const QString &fileName)
 Returns true if the file specified by fileName exists; otherwise returns false.
 
static QString symLinkTarget (const QString &fileName)
 
static bool remove (const QString &fileName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Removes the file specified by the fileName given.
 
static bool moveToTrash (const QString &fileName, QString *pathInTrash=nullptr)
 
static bool rename (const QString &oldName, const QString &newName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Renames the file oldName to newName.
 
static bool link (const QString &fileName, const QString &newName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a link named linkName that points to the file fileName.
 
static bool copy (const QString &fileName, const QString &newName)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Copies the file named fileName to newName.
 
static bool resize (const QString &filename, qint64 sz)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets fileName to size (in bytes) sz.
 
static Permissions permissions (const QString &filename)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the complete OR-ed together combination of QFile::Permission for fileName.
 
static bool setPermissions (const QString &filename, Permissions permissionSpec)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the permissions for fileName file to permissions.
 
- 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 Member Functions

 QFile (QFilePrivate &dd, QObject *parent=nullptr)
 
- Protected Member Functions inherited from QFileDevice
 QFileDevice ()
 
 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 readData (char *data, qint64 maxlen)=0
 Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred.
 
virtual qint64 readLineData (char *data, qint64 maxlen)
 Reads up to maxSize characters into data and returns the number of characters read.
 
virtual qint64 skipData (qint64 maxSize)
 
virtual qint64 writeData (const char *data, qint64 len)=0
 Writes up to maxSize bytes from data to the device.
 
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
 

Friends

class QTemporaryFile
 

Additional Inherited Members

- Public Types inherited from QFileDevice
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 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.
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

\inmodule QtCore

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

\reentrant

QFile is an I/O device for reading and writing text and binary files and \l{The Qt Resource System}{resources}. A QFile may be used by itself or, more conveniently, with a QTextStream or QDataStream.

The file name is usually passed in the constructor, but it can be set at any time using setFileName(). QFile expects the file separator to be '/' regardless of operating system. The use of other separators (e.g., '\') is not supported.

You can check for a file's existence using exists(), and remove a file using remove(). (More advanced file system related operations are provided by QFileInfo and QDir.)

The file is opened with open(), closed with close(), and flushed with flush(). Data is usually read and written using QDataStream or QTextStream, but you can also call the QIODevice-inherited functions read(), readLine(), readAll(), write(). QFile also inherits getChar(), putChar(), and ungetChar(), which work one character at a time.

The size of the file is returned by size(). You can get the current file position using pos(), or move to a new file position using seek(). If you've reached the end of the file, atEnd() returns true.

Definition at line 92 of file qfile.h.

Constructor & Destructor Documentation

◆ QFile() [1/5]

QFile::QFile ( )

Constructs a QFile object.

Definition at line 216 of file qfile.cpp.

Referenced by copy(), link(), permissions(), remove(), rename(), resize(), and setPermissions().

+ Here is the caller graph for this function:

◆ QFile() [2/5]

QFile::QFile ( const QString name)
Constructs a new file object to represent the file with the given \a name.

! [qfile-explicit-constructor-note]

Note
In versions up to and including Qt 6.8, this constructor is implicit, for backward compatibility. Starting from Qt 6.9 this constructor is unconditionally {explicit}. Users can force this constructor to be {explicit} even in earlier versions of Qt by defining the {QT_EXPLICIT_QFILE_CONSTRUCTION_FROM_PATH} macro before including any Qt header. ! [qfile-explicit-constructor-note]

Definition at line 239 of file qfile.cpp.

References d.

◆ QFile() [3/5]

QFile::QFile ( QObject parent)
explicit

Constructs a new file object with the given parent.

Definition at line 223 of file qfile.cpp.

◆ QFile() [4/5]

QFile::QFile ( const QString name,
QObject parent 
)

Constructs a new file object with the given parent to represent the file with the specified name.

Definition at line 249 of file qfile.cpp.

References d.

◆ ~QFile()

QFile::~QFile ( )

Destroys the file object, closing it if necessary.

Definition at line 267 of file qfile.cpp.

◆ QFile() [5/5]

QFile::QFile ( QFilePrivate dd,
QObject parent = nullptr 
)
protected

Definition at line 258 of file qfile.cpp.

Member Function Documentation

◆ copy() [1/2]

bool QFile::copy ( const QString fileName,
const QString newName 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Copies the file named fileName to newName.

Note
On Android, this operation is not yet supported for content scheme URIs.
See also
rename()

Definition at line 857 of file qfile.cpp.

References QFile(), and fileName.

+ Here is the call graph for this function:

◆ copy() [2/2]

bool QFile::copy ( const QString newName)

Copies the file named fileName() to newName.

Note
On Android, this operation is not yet supported for content scheme URIs.
See also
setFileName()

Definition at line 744 of file qfile.cpp.

References arg, QFileDevice::atEnd(), QFileDevice::close(), QFileDevice::CopyError, d, QFileDevice::error(), exists(), fileName, QFileDevice::NoError, open(), out, permissions(), qWarning, QIODevice::read(), QIODeviceBase::ReadOnly, QIODeviceBase::ReadWrite, setPermissions(), size(), QDir::tempPath(), tr, and QFileDevice::unsetError().

Referenced by copyFileIfNewer(), copyFilePrintStatus(), copyPackage(), QSSGQmlUtilities::copyTextureAsset(), QFileSystemModel::dropMimeData(), signPackage(), updateFile(), and updateFile().

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

◆ decodeName() [1/2]

QString QFile::decodeName ( const char *  localFileName)
inlinestatic

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the Unicode version of the given localFileName.

See encodeName() for details.

Definition at line 166 of file qfile.h.

References QString::fromLocal8Bit().

+ Here is the call graph for this function:

◆ decodeName() [2/2]

◆ encodeName()

QByteArray QFile::encodeName ( const QString fileName)
inlinestatic

Converts fileName to an 8-bit encoding that you can use in native APIs.

On Windows, the encoding is the one from active Windows (ANSI) codepage. On other platforms, this is UTF-8, for \macos in decomposed form (NFD).

See also
decodeName()

Definition at line 158 of file qfile.h.

References fileName.

Referenced by QBsdKeyboardHandler::QBsdKeyboardHandler(), QBsdMouseHandler::QBsdMouseHandler(), QLocalSocketPrivate::_q_connectToSocket(), QFontconfigDatabase::addApplicationFont(), QFseventsFileSystemWatcherEngine::addPaths(), QInotifyFileSystemWatcherEngine::addPaths(), QKqueueFileSystemWatcherEngine::addPaths(), QZipWriter::addSymLink(), QTestPrivate::canHandleUnicodeFileNames(), combinePath(), QFileSystemEngine::createDirectory(), encodeFileName(), escapeAndEncodeDependencyPath(), QFreeTypeFontDatabase::fontEngine(), QFontconfigDatabase::fontEngine(), freeDesktopTrashLocation(), QWindowsFontEngine::getCMap(), QFileSystemEngine::getLinkTarget(), isCaseSensitiveFileSystem(), loadTzTimeZones(), main(), QFileDialogPrivate::maxNameLength(), QMimeDatabasePrivate::mimeTypeForFile(), QHaikuServices::openDocument(), openFramebufferDevice(), openTtyDevice(), QFreeTypeFontDatabase::populateFontDatabase(), QAndroidPlatformFontDatabase::populateFontDatabase(), prefixMessage(), QGstreamerMediaEncoder::record(), QDynamicFileResourceRoot::registerSelf(), QFileSystemEngine::removeDirectory(), QLockFilePrivate::removeStaleLock(), runMoc(), QLockFilePrivate::tryLock_sys(), and QLibraryPrivate::updatePluginState().

+ Here is the caller graph for this function:

◆ exists() [1/2]

bool QFile::exists ( ) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns true if the file specified by fileName() exists; otherwise returns false.

See also
fileName(), setFileName()

Definition at line 351 of file qfile.cpp.

References d, QAbstractFileEngine::ExistsFlag, QAbstractFileEngine::FlagsMask, and QAbstractFileEngine::Refresh.

Referenced by QIconTheme::QIconTheme(), QQmlImportDatabase::QQmlImportDatabase(), QFileDialogPrivate::_q_createDirectory(), absoluteFilePath(), QQmlTypeLoader::absoluteFilePath(), QQmlImportDatabase::addImportPath(), QQmlImportDatabase::addPluginPath(), QCoreApplicationPrivate::appendApplicationPathToLibraryPaths(), QQuickSpriteEngine::assembledImage(), boo(), QmlLsp::QQmlCodeModel::buildPathsForFileUrl(), QImageWriter::canWrite(), checkSourceIsFile(), containsApplicationBinary(), copy(), copyDylib(), copyFileIfNewer(), copyFilePrintStatus(), copyFramework(), copyQtFiles(), copyStdCpp(), QSSGQmlUtilities::copyTextureAsset(), createDiskImage(), createQtConf(), createRcc(), deployQmlImports(), QZipReader::extractAll(), fileArchitecture(), findAppBinary(), findFile(), QQuickControlsTestUtils::forEachControl(), QDirectFbBlitterPlatformPixmap::fromFile(), getBinaryDependencies(), getQtLibsFromElf(), QPlaceManagerEngineNokiaV2::icon(), QGeoSatelliteInfoSourceGypsy::init(), QLinuxFbScreen::initialize(), linkFilePrintStatus(), QMimeBinaryProvider::loadMimeTypePrivate(), QSSGShaderLibraryManager::loadPregeneratedShaderInfo(), loadTzTimeZones(), main(), QNetworkFile::open(), QNetworkAccessFileBackend::open(), QQmlLocalStorage::openDatabaseSync(), parseOtoolLibraryLine(), qt_findAtNxFile(), quick_test_main_with_setup(), readAndroidDependencyXml(), readFileContent(), readInputFile(), rename(), QDir::rename(), QOffscreenIntegration::resolveConfigFileConfiguration(), QQuickStyleSpec::resolveConfigFilePath(), runAdb(), runRcc(), scanImports(), QFileSelectorPrivate::selectionHelper(), QQuickStylePrivate::settings(), signAAB(), signPackage(), QNetworkDiskCachePrivate::storeItem(), QFileDialogPrivate::typedFiles(), updateAndroidManifest(), updateLibsXml(), updateStringsXml(), QQmlJS::Dom::FileWriter::write(), and zipalignPath().

◆ exists() [2/2]

bool QFile::exists ( const QString fileName)
static

Returns true if the file specified by fileName exists; otherwise returns false.

Note
If fileName is a symlink that points to a non-existing file, false is returned.

Definition at line 368 of file qfile.cpp.

References QFileInfo::exists(), and fileName.

+ Here is the call graph for this function:

◆ fileName()

◆ link() [1/2]

bool QFile::link ( const QString fileName,
const QString linkName 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates a link named linkName that points to the file fileName.

What a link is depends on the underlying filesystem (be it a shortcut on Windows or a symbolic link on Unix). Returns true if successful; otherwise returns false.

See also
link()

Definition at line 727 of file qfile.cpp.

References QFile(), and fileName.

+ Here is the call graph for this function:

◆ link() [2/2]

bool QFile::link ( const QString linkName)

Creates a link named linkName that points to the file currently specified by fileName().

What a link is depends on the underlying filesystem (be it a shortcut on Windows or a symbolic link on Unix). Returns true if successful; otherwise returns false.

This function will not overwrite an already existing entity in the file system; in this case, link() will return false and set \l{QFile::}{error()} to return \l{QFile::}{RenameError}.

Note
To create a valid link on Windows, linkName must have a {.lnk} file extension.
See also
setFileName()

Definition at line 699 of file qfile.cpp.

References QFileInfo::absoluteFilePath(), d, fi, fileName, qWarning, QFileDevice::RenameError, and QFileDevice::unsetError().

Referenced by createSymbolicLink(), QFileSystemModel::dropMimeData(), QZipReader::extractAll(), and linkFilePrintStatus().

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

◆ moveToTrash() [1/2]

bool QFile::moveToTrash ( )
Since
5.15

Moves the file specified by fileName() to the trash. Returns true if successful, and sets the fileName() to the path at which the file can be found within the trash; otherwise returns false.

Note
On systems where the system API doesn't report the location of the file in the trash, fileName() will be set to the null string once the file has been moved. On systems that don't have a trash can, this function always returns false.

Definition at line 467 of file qfile.cpp.

References QFileDevice::close(), d, QFileDevice::error(), QFileSystemEntry::filePath(), QFSFileEngine::isUnnamedFile(), QFileSystemEngine::moveFileToTrash(), QFileDevice::NoError, qWarning, QFileDevice::RenameError, setFileName(), and QFileDevice::unsetError().

Referenced by moveToTrash().

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

◆ moveToTrash() [2/2]

bool QFile::moveToTrash ( const QString fileName,
QString pathInTrash = nullptr 
)
static
Since
5.15 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Moves the file specified by fileName() to the trash. Returns true if successful, and sets pathInTrash (if provided) to the path at which the file can be found within the trash; otherwise returns false.

Note
On systems where the system API doesn't report the path of the file in the trash, pathInTrash will be set to the null string once the file has been moved. On systems that don't have a trash can, this function always returns false.

Definition at line 504 of file qfile.cpp.

References file, fileName(), fileName, and moveToTrash().

+ Here is the call graph for this function:

◆ open() [1/4]

bool QFile::open ( FILE *  fh,
OpenMode  mode,
FileHandleFlags  handleFlags = DontCloseHandle 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Opens the existing file handle fh in the given mode.

handleFlags may be used to specify additional options. Returns true if successful; otherwise returns false.

Example:

#include <stdio.h>
void printError(const char* msg)
{
file.write(msg, qstrlen(msg)); // write to stderr
}
void close() override
Calls QFileDevice::flush() and closes the file.
\inmodule QtCore
Definition qfile.h:93
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
Definition qfile.cpp:881
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
size_t qstrlen(const char *str)
QFile file
[0]
void printError(const char *msg)
[0]

When a QFile is opened using this function, behaviour of close() is controlled by the AutoCloseHandle flag. If AutoCloseHandle is specified, and this function succeeds, then calling close() closes the adopted handle. Otherwise, close() does not actually close the file, but only flushes it.

{Warning:} \list 1

  • If fh does not refer to a regular file, e.g., it is stdin, stdout, or stderr, you may not be able to seek(). size() returns 0 in those cases. See QIODevice::isSequential() for more information.
  • Since this function opens the file without specifying the file name, you cannot use this QFile with a QFileInfo. \endlist
See also
close()

{Note for the Windows Platform}

fh must be opened in binary mode (i.e., the mode string must contain 'b', as in "rb" or "wb") when accessing files and other random-access devices. Qt will translate the end-of-line characters if you pass QIODevice::Text to mode. Sequential devices, such as stdin and stdout, are unaffected by this limitation.

You need to enable support for console applications in order to use the stdin, stdout and stderr streams at the console. To do this, add the following declaration to your application's project file:

CONFIG += console

Definition at line 996 of file qfile.cpp.

References QIODeviceBase::Append, d, file_already_open(), QIODevice::isOpen(), QFileDevice::isSequential(), QIODeviceBase::NewOnly, QIODevice::open(), QFileDevice::pos(), qWarning, QIODeviceBase::ReadOnly, QIODevice::seek(), QIODeviceBase::Unbuffered, QFileDevice::unsetError(), and QIODeviceBase::WriteOnly.

+ Here is the call graph for this function:

◆ open() [2/4]

bool QFile::open ( int  fd,
OpenMode  mode,
FileHandleFlags  handleFlags = DontCloseHandle 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Opens the existing file descriptor fd in the given mode.

handleFlags may be used to specify additional options. Returns true if successful; otherwise returns false.

When a QFile is opened using this function, behaviour of close() is controlled by the AutoCloseHandle flag. If AutoCloseHandle is specified, and this function succeeds, then calling close() closes the adopted handle. Otherwise, close() does not actually close the file, but only flushes it.

Warning
If fd is not a regular file, e.g, it is 0 (stdin), 1 (stdout), or 2 (stderr), you may not be able to seek(). In those cases, size() returns 0. See QIODevice::isSequential() for more information.
Since this function opens the file without specifying the file name, you cannot use this QFile with a QFileInfo.
See also
close()

Definition at line 1048 of file qfile.cpp.

References QIODeviceBase::Append, d, file_already_open(), QIODevice::isOpen(), QFileDevice::isSequential(), QIODeviceBase::NewOnly, QIODevice::open(), QFileDevice::pos(), qWarning, QIODeviceBase::ReadOnly, QIODevice::seek(), QIODeviceBase::Unbuffered, QFileDevice::unsetError(), and QIODeviceBase::WriteOnly.

+ Here is the call graph for this function:

◆ open() [3/4]

bool QFile::open ( OpenMode  mode)
override

Opens the file using OpenMode mode, returning true if successful; otherwise false.

The mode must be QIODevice::ReadOnly, QIODevice::WriteOnly, or QIODevice::ReadWrite. It may also have additional flags, such as QIODevice::Text and QIODevice::Unbuffered.

Note
In \l{QIODevice::}{WriteOnly} or \l{QIODevice::}{ReadWrite} mode, if the relevant file does not already exist, this function will try to create a new file before opening it. The file will be created with mode 0666 masked by the umask on POSIX systems, and with permissions inherited from the parent directory on Windows. On Android, it's expected to have access permission to the parent of the file name, otherwise, it won't be possible to create this non-existing file.
See also
QIODevice::OpenMode, setFileName()

Definition at line 881 of file qfile.cpp.

References QIODeviceBase::Append, d, file_already_open(), QIODevice::isOpen(), QIODeviceBase::NewOnly, QIODevice::open(), QFileDevice::OpenError, qWarning, QIODeviceBase::ReadOnly, QFileDevice::seek(), size(), QIODeviceBase::Unbuffered, QFileDevice::unsetError(), QFileDevice::UnspecifiedError, and QIODeviceBase::WriteOnly.

Referenced by AssimpImporter::AssimpImporter(), Base64IconStore::Base64IconStore(), QColorOutputPrivate::QColorOutputPrivate(), QIBusPlatformInputContext::QIBusPlatformInputContext(), QIconCacheGtkReader::QIconCacheGtkReader(), QtWaylandClient::QWaylandShmBuffer::QWaylandShmBuffer(), QGeoFileTileCache::~QGeoFileTileCache(), activityFromAndroidManifest(), QWindowsDirectWriteFontDatabase::addApplicationFont(), QGeoFileTileCache::addToDiskCache(), QAbstractGeoTileCache::baseCacheDirectory(), QPdfEngine::begin(), bluetoothdVersion(), checkForDrmPermission(), QOpenGLShader::compileSourceFile(), QTlsPrivate::TlsCryptographOpenSSL::continueHandshake(), copy(), QIBusPlatformInputContextPrivate::createConnection(), QTemporaryFile::createNativeFile(), createProject(), createQtConf(), QNetworkDiskCache::data(), QTranslatorPrivate::do_load(), dumpOutput(), QQmlJS::Dom::DomUniverse::execQueue(), QBenchmarkValgrindUtils::extractResult(), FileContent(), QNetworkDiskCache::fileMetaData(), findPatternUnloaded(), QSslCertificate::fromPath(), QmlTypesCreator::generate(), QFreetypeFace::getFace(), QGeoFileTileCache::getFromDisk(), QGeoFileTileCacheOsm::getFromOfflineStorage(), getLibraryProjectsInOutputFolder(), QFileDialog::getOpenFileContent(), getRequestedDisplays(), QSSGInputUtil::getStreamForFile(), gradleBuildFlags(), QImageReader::imageFormat(), AssimpImporter::import(), QCss::Parser::init(), QImageReaderPrivate::initHandler(), isTzFile(), QConfFile::isWritable(), QQmlJSLinter::lintFile(), QMimeBinaryProvider::CacheFile::load(), QDefaultOutputMapping::load(), QQuickBorderImage::load(), QSvgTinyDocument::load(), QMimeXMLProvider::load(), QGtk3Json::load(), QQmlFile::load(), QQmlFile::load(), QSSGLoadedTexture::loadCompressedImage(), QKmsScreenConfig::loadConfig(), QRawFont::loadFromFile(), loadMapObject(), QMimeBinaryProvider::loadMimeTypePrivate(), loadModelBlendParticleMesh(), loadModelShapeMesh(), loadRulesFromFile(), QGeoFileTileCache::loadTiles(), loadTzTimeZones(), QHostInfo::localDomainName(), lookupVendorIdInSystemDatabase(), ElfMapper::map(), mergeGradleProperties(), QSSGQmlUtilities::meshAssetName(), moduleFromJsonFile(), noStream_snippet(), QNetworkFile::open(), QNetworkAccessFileBackend::open(), QTemporaryFile::open(), MainWindow::openFile(), openFile(), QPdfPrintEnginePrivate::openPrintDevice(), QCupsPrintEnginePrivate::openPrintDevice(), QQmlJSTypeReader::operator()(), QSSGQmlUtilities::outputTextureAsset(), packageNameFromAndroidManifest(), packageNameFromAndroidManifest(), VkSpecParser::parse(), CategoryParser::parse(), Recognizer::parse(), QTestPrivate::parseBlackList(), parseMountInfo(), Moc::parsePluginData(), patch_debugInInfoPlist(), patchQtCore(), QWasmFontDatabase::populateFontDatabase(), printError(), Scanner::process(), MetaTypesJsonProcessor::processForeignTypes(), QSvgHandler::processingInstruction(), QQmlTypeLoader::qmldirContent(), qRelocateResourceFile(), queryQtPaths(), quick_test_main_with_setup(), QWasmIDBSettingsPrivate_onLoad(), readAndroidDependencyXml(), QCacheUtils::readCachedMesh(), QCacheUtils::readCookedMesh(), QWavefrontMesh::readData(), readFileContent(), RCCResourceLibrary::readFiles(), readGpuFeatures(), readGradleProperties(), readInputFile(), readRegularEmptyFile_snippet(), readTextStream_snippet(), readTranslationsCatalogs(), QDynamicFileResourceRoot::registerSelf(), QQmlXmlListModel::reload(), rename(), renderToKTXFileInternal(), QOffscreenIntegration::resolveConfigFileConfiguration(), QmlTypeRegistrar::runExtract(), runRcc(), QGtk3Json::save(), QFileDialog::saveFileContent(), QSslSocket::setLocalCertificate(), QMediaPlayerPrivate::setMedia(), QSslSocket::setPrivateKey(), QWasmAudioOutput::setSource(), QWasmVideoOutput::setSource(), AudioInputExample::setup(), AudioOutputExample::setup(), QWasmIDBSettingsPrivate::sync(), QWasmIDBSettingsPrivate::syncToLocal(), updateAndroidManifest(), updateFile(), updateStringsXml(), verifyString(), TestHTTPServer::wait(), wrapInFunction(), QQmlJS::Dom::FileWriter::write(), QCacheUtils::writeCachedMesh(), RCCFileInfo::writeDataBlob(), writeDataStream_snippet(), writeDependencyFile(), QTextOdfWriter::writeInlineCharacter(), QSSGQmlUtilities::writeQmlForAnimation(), and writeTextStream_snippet().

+ Here is the call graph for this function:

◆ open() [4/4]

bool QFile::open ( OpenMode  flags,
Permissions  permissions 
)

◆ permissions() [1/2]

QFile::Permissions QFile::permissions ( ) const
overridevirtual

\reimp

Reimplemented from QFileDevice.

Definition at line 1107 of file qfile.cpp.

References QFileDevice::permissions().

Referenced by copy(), copyFilePrintStatus(), QDir::removeRecursively(), rename(), setPermissions(), setPermissions(), and updateFile().

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

◆ permissions() [2/2]

QFile::Permissions QFile::permissions ( const QString filename)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the complete OR-ed together combination of QFile::Permission for fileName.

Definition at line 1120 of file qfile.cpp.

References QFile(), and fileName.

+ Here is the call graph for this function:

◆ remove() [1/2]

bool QFile::remove ( )

Removes the file specified by fileName().

Returns true if successful; otherwise returns false.

The file is closed before it is removed.

See also
setFileName()

Definition at line 419 of file qfile.cpp.

References QFileDevice::close(), d, QFileDevice::error(), QFSFileEngine::isUnnamedFile(), QFileDevice::NoError, qWarning, QFileDevice::RemoveError, and QFileDevice::unsetError().

Referenced by DeferredFileRemove::~DeferredFileRemove(), QTemporaryFile::~QTemporaryFile(), QAbstractGeoTileCache::baseCacheDirectory(), QImageWriter::canWrite(), cleanedAssetPath(), QBenchmarkValgrindUtils::cleanup(), cleanupTemporaryItemCopies(), QGeoFileTileCache::clearMapId(), QCupsPrintEnginePrivate::closePrintDevice(), copyFilePrintStatus(), copyPackage(), createDiskImage(), createRcc(), deleteMissingFiles(), QGeoFileTileCache::evictFromDiskCache(), QNetworkDiskCache::expire(), main(), mergeGradleProperties(), QDir::relativeFilePath(), QFileSystemModel::remove(), QDir::remove(), QNetworkDiskCachePrivate::removeFile(), QDir::removeRecursively(), rename(), signPackage(), QLockFilePrivate::tryLock_sys(), QLockFile::unlock(), QQsbIODeviceCollection::unmap(), updateFile(), updateFile(), and QQmlJS::Dom::FileWriter::write().

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

◆ remove() [2/2]

bool QFile::remove ( const QString fileName)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Removes the file specified by the fileName given.

Returns true if successful; otherwise returns false.

See also
remove()

Definition at line 450 of file qfile.cpp.

References QFile(), and fileName.

+ Here is the call graph for this function:

◆ rename() [1/2]

bool QFile::rename ( const QString newName)

Renames the file currently specified by fileName() to newName.

Returns true if successful; otherwise returns false.

If a file with the name newName already exists, rename() returns false (i.e., QFile will not overwrite it).

The file is closed before it is renamed.

If the rename operation fails, Qt will attempt to copy this file's contents to newName, and then remove this file, keeping only newName. If that copy operation fails or this file can't be removed, the destination file newName is removed to restore the old state.

See also
setFileName()

Definition at line 533 of file qfile.cpp.

References arg, Qt::CaseInsensitive, QFileDevice::close(), d, QFileDevice::error(), QIODevice::errorString(), exists(), fileId(), fileName, QFileSystemEntry::filePath(), QTemporaryFileName::generateNext(), QFileSystemEngine::id(), QByteArray::isNull(), QFileDevice::isSequential(), QFileDevice::NoError, open(), out, permissions(), qWarning, QIODevice::read(), QIODeviceBase::ReadOnly, remove(), QFileDevice::RenameError, QFileSystemEngine::renameFile(), setFileName(), setPermissions(), QDir::toNativeSeparators(), QSystemError::toString(), tr, QIODeviceBase::Truncate, QFileDevice::unsetError(), and QIODeviceBase::WriteOnly.

Referenced by createRcc(), QFileSystemModel::dropMimeData(), mergeGradleProperties(), QTemporaryFile::rename(), QDir::rename(), wrapper(), and QQmlJS::Dom::FileWriter::write().

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

◆ rename() [2/2]

bool QFile::rename ( const QString oldName,
const QString newName 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Renames the file oldName to newName.

Returns true if successful; otherwise returns false.

If a file with the name newName already exists, rename() returns false (i.e., QFile will not overwrite it).

See also
rename()

Definition at line 677 of file qfile.cpp.

References QFile().

+ Here is the call graph for this function:

◆ resize() [1/2]

bool QFile::resize ( const QString fileName,
qint64  sz 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets fileName to size (in bytes) sz.

Returns true if the resize succeeds; false otherwise. If sz is larger than fileName 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
resize()

Definition at line 1099 of file qfile.cpp.

References QFile(), and fileName.

+ Here is the call graph for this function:

◆ resize() [2/2]

bool QFile::resize ( qint64  sz)
overridevirtual

\reimp

Reimplemented from QFileDevice.

Definition at line 1080 of file qfile.cpp.

References QFileDevice::resize().

+ Here is the call graph for this function:

◆ setFileName()

void QFile::setFileName ( const QString name)

Sets the name of the file.

The name can have no path, a relative path, or an absolute path.

Do not call this function if the file has already been opened.

If the file name has no path or a relative path, the path used will be the application's current directory path {at the time of the open()} call.

Example:

file.setFileName("readme.txt");
file.open(QIODevice::ReadOnly); // opens "/home/readme.txt" under Unix
static bool setCurrent(const QString &path)
Sets the application's current working directory to path.
Definition qdir.cpp:2027
void setFileName(const QString &name)
Sets the name of the file.
Definition qfile.cpp:302

Note that the directory separator "/" works for all operating systems supported by Qt.

See also
fileName(), QFileInfo, QDir
Since
6.0 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 302 of file qfile.cpp.

References QFileDevice::close(), d, file_already_open(), and QIODevice::isOpen().

Referenced by QIconCacheGtkReader::QIconCacheGtkReader(), QIconTheme::QIconTheme(), createProject(), QImageReaderPrivate::initHandler(), QHostInfo::localDomainName(), moveToTrash(), QNetworkAccessFileBackend::open(), openFile(), VkSpecParser::parse(), RCCResourceLibrary::readFiles(), rename(), runRcc(), AudioInputExample::setup(), AudioOutputExample::setup(), and QQmlJS::Dom::FileWriter::write().

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

◆ setPermissions() [1/2]

bool QFile::setPermissions ( const QString filename,
Permissions  permissionSpec 
)
static

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the permissions for fileName file to permissions.

Definition at line 1148 of file qfile.cpp.

References QFile(), fileName, and permissions().

+ Here is the call graph for this function:

◆ setPermissions() [2/2]

bool QFile::setPermissions ( Permissions  permissions)
overridevirtual

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(), setFileName()

Reimplemented from QFileDevice.

Definition at line 1136 of file qfile.cpp.

References permissions(), and QFileDevice::setPermissions().

Referenced by copy(), copyFilePrintStatus(), QZipReader::extractAll(), freeDesktopTrashLocation(), QDir::removeRecursively(), rename(), and updateFile().

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

◆ size()

qint64 QFile::size ( ) const
overridevirtual

\reimp

Reimplemented from QIODevice.

Definition at line 1156 of file qfile.cpp.

References QFileDevice::size().

Referenced by QIconCacheGtkReader::QIconCacheGtkReader(), copy(), QTranslatorPrivate::do_load(), findInPath(), findPatternUnloaded(), QMimeBinaryProvider::CacheFile::load(), ElfMapper::map(), open(), Preprocessor::preprocessed(), qtiffMapProc(), QCacheUtils::readCachedMesh(), QCacheUtils::readCookedMesh(), readOrMapFile(), QDynamicFileResourceRoot::registerSelf(), Decoder::setSource(), and QCacheUtils::writeCachedMesh().

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

◆ symLinkTarget() [1/2]

QString QFile::symLinkTarget ( ) const
Since
4.2 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Returns the absolute path of the file or directory a symlink (or shortcut on Windows) points to, or a an empty string if the object isn't a symbolic link.

This name may not represent an existing file; it is only a string. QFile::exists() returns true if the symlink points to an existing file.

See also
fileName(), setFileName()

Definition at line 387 of file qfile.cpp.

References QAbstractFileEngine::AbsoluteLinkTarget, and d.

◆ symLinkTarget() [2/2]

QString QFile::symLinkTarget ( const QString fileName)
static
Since
4.2

Returns the absolute path of the file or directory referred to by the symlink (or shortcut on Windows) specified by fileName, or returns an empty string if the fileName does not correspond to a symbolic link.

This name may not represent an existing file; it is only a string. QFile::exists() returns true if the symlink points to an existing file.

Definition at line 404 of file qfile.cpp.

References fileName, and QFileInfo::symLinkTarget().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QTemporaryFile

friend class QTemporaryFile
friend

Definition at line 323 of file qfile.h.


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