QtBase  v6.3.1
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
QFile Class Reference

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

#include <qfile.h>

Inheritance diagram for QFile:
Inheritance graph
[legend]
Collaboration diagram for QFile:
Collaboration graph
[legend]

Public Member Functions

 QFile ()
 
 QFile (const QString &name)
 
 QFile (QObject *parent)
 
 QFile (const QString &name, QObject *parent)
 
 ~QFile ()
 
QString fileName () const override
 
void setFileName (const QString &name)
 
bool exists () const
 
QString symLinkTarget () const
 
bool remove ()
 
bool moveToTrash ()
 
bool rename (const QString &newName)
 
bool link (const QString &newName)
 
bool copy (const QString &newName)
 
bool open (OpenMode flags) override
 
bool open (OpenMode flags, Permissions permissions)
 
bool open (FILE *f, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle)
 
bool open (int fd, OpenMode ioFlags, FileHandleFlags handleFlags=DontCloseHandle)
 
qint64 size () const override
 
bool resize (qint64 sz) override
 
Permissions permissions () const override
 
bool setPermissions (Permissions permissionSpec) override
 
- Public Member Functions inherited from QFileDevice
 ~QFileDevice ()
 
FileError error () const
 
void unsetError ()
 
void close () override
 
bool isSequential () const override
 
int handle () const
 
qint64 pos () const override
 
bool seek (qint64 offset) override
 
bool atEnd () const override
 
bool flush ()
 
qint64 size () const override
 
ucharmap (qint64 offset, qint64 size, MemoryMapFlags flags=NoOptions)
 
bool unmap (uchar *address)
 
QDateTime fileTime (QFileDevice::FileTime time) const
 
bool setFileTime (const QDateTime &newDate, QFileDevice::FileTime fileTime)
 
- Public Member Functions inherited from QIODevice
 QIODevice ()
 
 QIODevice (QObject *parent)
 
virtual ~QIODevice ()
 
QIODeviceBase::OpenMode openMode () const
 
void setTextModeEnabled (bool enabled)
 
bool isTextModeEnabled () const
 
bool isOpen () const
 
bool isReadable () const
 
bool isWritable () const
 
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)
 
virtual bool reset ()
 
virtual qint64 bytesAvailable () const
 
virtual qint64 bytesToWrite () const
 
qint64 read (char *data, qint64 maxlen)
 
QByteArray read (qint64 maxlen)
 
QByteArray readAll ()
 
qint64 readLine (char *data, qint64 maxlen)
 
QByteArray readLine (qint64 maxlen=0)
 
virtual bool canReadLine () const
 
void startTransaction ()
 
void commitTransaction ()
 
void rollbackTransaction ()
 
bool isTransactionStarted () const
 
qint64 write (const char *data, qint64 len)
 
qint64 write (const char *data)
 
qint64 write (const QByteArray &data)
 
qint64 peek (char *data, qint64 maxlen)
 
QByteArray peek (qint64 maxlen)
 
qint64 skip (qint64 maxSize)
 
virtual bool waitForReadyRead (int msecs)
 
virtual bool waitForBytesWritten (int msecs)
 
void ungetChar (char c)
 
bool putChar (char c)
 
bool getChar (char *c)
 
QString errorString () const
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 
virtual ~QObject ()
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const
 
void setObjectName (const QString &name)
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 
bool isWindowType () const
 
bool signalsBlocked () const noexcept
 
bool blockSignals (bool b) noexcept
 
QThreadthread () const
 
void moveToThread (QThread *thread)
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 
template<typename T >
T findChild (const QString &aName=QString(), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (const QString &aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<typename T >
QList< TfindChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
const QObjectListchildren () const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
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
 
void dumpObjectInfo () const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 
bool inherits (const char *classname) const
 

Static Public Member Functions

static QByteArray encodeName (const QString &fileName)
 
static QString decodeName (const QByteArray &localFileName)
 
static QString decodeName (const char *localFileName)
 
static bool exists (const QString &fileName)
 
static QString symLinkTarget (const QString &fileName)
 
static bool remove (const QString &fileName)
 
static bool moveToTrash (const QString &fileName, QString *pathInTrash=nullptr)
 
static bool rename (const QString &oldName, const QString &newName)
 
static bool link (const QString &fileName, const QString &newName)
 
static bool copy (const QString &fileName, const QString &newName)
 
static bool resize (const QString &filename, qint64 sz)
 
static Permissions permissions (const QString &filename)
 
static bool setPermissions (const QString &filename, Permissions permissionSpec)
 
- 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)
 
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::FunctionPointer< Func2 >::Object *receiver, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
static QMetaObject::Connection ::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 slot)
 
template<typename Func1 , typename Func2 >
static std::enable_if< QtPrivate::FunctionPointer< Func2 >::ArgumentCount==-1 &&!std::is_convertible_v< Func2, const char * >, QMetaObject::Connection >::type connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *context, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::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
 
qint64 writeData (const char *data, qint64 len) override
 
qint64 readLineData (char *data, qint64 maxlen) override
 
- Protected Member Functions inherited from QIODevice
 QIODevice (QIODevicePrivate &dd, QObject *parent=nullptr)
 
virtual qint64 skipData (qint64 maxSize)
 
void setOpenMode (QIODeviceBase::OpenMode openMode)
 
void setErrorString (const QString &errorString)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
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
}
 
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
}
 
enum  FileHandleFlag { AutoCloseHandle = 0x0001 , DontCloseHandle = 0 }
 
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
}
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Signals inherited from QIODevice
void readyRead ()
 
void channelReadyRead (int channel)
 
void bytesWritten (qint64 bytes)
 
void channelBytesWritten (int channel, qint64 bytes)
 
void aboutToClose ()
 
void readChannelFinished ()
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object More...
 

Detailed Description

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

\inmodule QtCore

\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 93 of file qfile.h.

Constructor & Destructor Documentation

◆ QFile() [1/5]

QFile::QFile ( )

Constructs a QFile object.

Definition at line 250 of file qfile.cpp.

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

Definition at line 264 of file qfile.cpp.

◆ QFile() [3/5]

QFile::QFile ( QObject parent)
explicit

Constructs a new file object with the given parent.

Definition at line 257 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 274 of file qfile.cpp.

◆ ~QFile()

QFile::~QFile ( )

Destroys the file object, closing it if necessary.

Definition at line 292 of file qfile.cpp.

◆ QFile() [5/5]

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

Definition at line 283 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.

See also
rename()

Definition at line 876 of file qfile.cpp.

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

◆ copy() [2/2]

bool QFile::copy ( const QString newName)

Copies the file named fileName() to newName.

See also
setFileName()

Definition at line 766 of file qfile.cpp.

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 167 of file qfile.h.

Here is the call graph for this function:

◆ decodeName() [2/2]

QString QFile::decodeName ( const QByteArray localFileName)
inlinestatic

This does the reverse of QFile::encodeName() using localFileName.

See also
encodeName()

Definition at line 163 of file qfile.h.

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

◆ encodeName()

QByteArray QFile::encodeName ( const QString fileName)
inlinestatic

Converts fileName to the local 8-bit encoding determined by the user's locale. This is sufficient for file names that the user chooses. File names hard-coded into the application should only use 7-bit ASCII filename characters.

See also
decodeName()

Definition at line 159 of file qfile.h.

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 376 of file qfile.cpp.

Here is the caller graph for this function:

◆ 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 393 of file qfile.cpp.

Here is the call graph for this function:

◆ fileName()

QString QFile::fileName ( ) const
overridevirtual

Returns the name set by setFileName() or to the QFile constructors.

See also
setFileName(), QFileInfo::fileName()

Reimplemented from QFileDevice.

Reimplemented in QTemporaryFile.

Definition at line 302 of file qfile.cpp.

Here is the caller graph for this function:

◆ 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 752 of file qfile.cpp.

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 724 of file qfile.cpp.

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 492 of file qfile.cpp.

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 529 of file qfile.cpp.

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:

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:

Definition at line 1012 of file qfile.cpp.

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 1064 of file qfile.cpp.

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.
See also
QIODevice::OpenMode, setFileName()

Definition at line 897 of file qfile.cpp.

Here is the call graph for this function:
Here is the caller 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 1123 of file qfile.cpp.

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 1136 of file qfile.cpp.

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 444 of file qfile.cpp.

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 475 of file qfile.cpp.

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 558 of file qfile.cpp.

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 702 of file qfile.cpp.

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 1115 of file qfile.cpp.

Here is the call graph for this function:

◆ resize() [2/2]

bool QFile::resize ( qint64  sz)
overridevirtual

\reimp

Reimplemented from QFileDevice.

Definition at line 1096 of file qfile.cpp.

Here is the call graph for this function:
Here is the caller 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:

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 327 of file qfile.cpp.

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  permissions 
)
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 1164 of file qfile.cpp.

◆ 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 1152 of file qfile.cpp.

Here is the caller graph for this function:

◆ size()

qint64 QFile::size ( ) const
overridevirtual

\reimp

Reimplemented from QIODevice.

Definition at line 1172 of file qfile.cpp.

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 412 of file qfile.cpp.

◆ 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 429 of file qfile.cpp.

Here is the call graph for this function:

Friends And Related Function Documentation

◆ QTemporaryFile

friend class QTemporaryFile
friend

Definition at line 324 of file qfile.h.


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