Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtCore.QFile Class Reference

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

Inheritance diagram for QtCore.QFile:
Collaboration diagram for QtCore.QFile:

Public Types

enum  FileError {
  AbortError = 6, CopyError = 14, FatalError = 3, NoError = 0,
  OpenError = 5, PermissionsError = 13, PositionError = 11, ReadError = 1,
  RemoveError = 9, RenameError = 10, ResizeError = 12, ResourceError = 4,
  TimeOutError = 7, UnspecifiedError = 8, WriteError = 2
}
  More...
 
enum  FileHandleFlag { AutoCloseHandle = 1, DontCloseHandle = 0 }
  More...
 
enum  MemoryMapFlags { NoOptions = 0 }
  More...
 
enum  Permission {
  ExeGroup = 16, ExeOther = 1, ExeOwner = 4096, ExeUser = 256,
  ReadGroup = 64, ReadOther = 4, ReadOwner = 16384, ReadUser = 1024,
  WriteGroup = 32, WriteOther = 2, WriteOwner = 8192, WriteUser = 512
}
  More...
 
- Public Types inherited from QtCore.QIODevice
enum  OpenModeFlag {
  Append = 4, NotOpen = 0, ReadOnly = 1, ReadWrite = 3,
  Text = 16, Truncate = 8, Unbuffered = 32, WriteOnly = 2
}
  More...
 

Public Member Functions

 QFile ()
 
 
 QFile (QObject parent)
 
 
 QFile (string name)
 
 
 QFile (string name, QObject parent)
 
 
override void CreateProxy ()
 
override bool AtEnd ()
 
 
override void Close ()
 
 
new bool Copy (string newName)
 
 
new QFile.FileError Error ()
 
 
new bool Exists ()
 
 
virtual QAbstractFileEngine FileEngine ()
 
new bool Flush ()
 
 
new int Handle ()
 
 
override bool IsSequential ()
 
 
new bool Link (string newName)
 
 
new Pointer< byte > Map (long offset, long size, QFile.MemoryMapFlags flags=QFile.MemoryMapFlags.NoOptions)
 
 
override bool Open (QIODevice.OpenModeFlag flags)
 
 
new bool Open (int fd, QIODevice.OpenModeFlag flags)
 
 
new bool Open (int fd, QIODevice.OpenModeFlag ioFlags, QFile.FileHandleFlag handleFlags)
 
 
new QFile.Permission Permissions ()
 
 
override long Pos ()
 
 
new string ReadLink ()
 
 
new bool Remove ()
 
 
new bool Rename (string newName)
 
 
new bool Resize (long sz)
 
 
override bool Seek (long offset)
 
 
new bool SetPermissions (QFile.Permission permissionSpec)
 
 
override long Size ()
 
 
new string SymLinkTarget ()
 
 
new bool Unmap (Pointer< byte > address)
 
 
new void UnsetError ()
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QIODevice
 QIODevice ()
 
 
 QIODevice (QObject parent)
 
 
override void CreateProxy ()
 
virtual long BytesAvailable ()
 
 
virtual long BytesToWrite ()
 
 
virtual bool CanReadLine ()
 
 
new string ErrorString ()
 
 
new bool GetChar (Pointer< sbyte > c)
 
 
new bool IsOpen ()
 
 
new bool IsReadable ()
 
 
new bool IsTextModeEnabled ()
 
 
new bool IsWritable ()
 
 
new QIODevice.OpenModeFlag OpenMode ()
 
 
new QByteArray Peek (long maxlen)
 
 
new long Peek (Pointer< sbyte > data, long maxlen)
 
 
new bool PutChar (sbyte c)
 
 
new QByteArray Read (long maxlen)
 
 
new long Read (Pointer< sbyte > data, long maxlen)
 
 
new QByteArray ReadAll ()
 
 
new QByteArray ReadLine (long maxlen=0)
 
 
new long ReadLine (Pointer< sbyte > data, long maxlen)
 
 
virtual bool Reset ()
 
 
new void SetTextModeEnabled (bool enabled)
 
 
new void UngetChar (sbyte c)
 
 
virtual bool WaitForBytesWritten (int msecs)
 
 
virtual bool WaitForReadyRead (int msecs)
 
 
new long Write (QByteArray data)
 
 
new long Write (string data)
 
 
new long Write (string data, long len)
 
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.QObject
 QObject (QObject parent=null)
 
 
new bool BlockSignals (bool b)
 
 
new
System.Collections.Generic.List
< QObject
Children ()
 
 
new bool Connect (QObject sender, string signal, string member, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
new void DeleteLater ()
 
 
new bool Disconnect (QObject receiver, string member=null)
 
 
new bool Disconnect (string signal=null, QObject receiver=null, string member=null)
 
 
new void DumpObjectInfo ()
 
 
new void DumpObjectTree ()
 
 
new
System.Collections.Generic.List
< QByteArray
DynamicPropertyNames ()
 
 
virtual bool OnEvent (QEvent arg1)
 
 
virtual bool EventFilter (QObject arg1, QEvent arg2)
 
 
new bool Inherits (string classname)
 
 
new void InstallEventFilter (QObject arg1)
 
 
new bool IsWidgetType ()
 
 
new void KillTimer (int id)
 
 
new object Property (string name)
 
 
new void RemoveEventFilter (QObject arg1)
 
 
new bool SetProperty (string name, object value)
 
 
new void SetUserData (uint id, QObjectUserData data)
 
new bool SignalsBlocked ()
 
 
new int StartTimer (int interval)
 
 
new QObjectUserData UserData (uint id)
 
new void Dispose ()
 
- Public Member Functions inherited from QtCore.Qt
delegate QTextStream FuncQTextStreamQTextStream (QTextStream qTextStream)
 
delegate string FuncStringQByteArray (QByteArray qByteArray)
 
delegate QByteArray FuncQByteArrayString (string @string)
 
delegate void ActionQtMsgTypeString (QtMsgType qtMsgType, string @string)
 
delegate QObject FuncQObject ()
 

Static Public Member Functions

static bool Copy (string fileName, string newName)
 
 
static string DecodeName (QByteArray localFileName)
 
 
static string DecodeName (string localFileName)
 
 
static QByteArray EncodeName (string fileName)
 
 
static bool Exists (string fileName)
 
 
static bool Link (string oldname, string newName)
 
 
static QFile.Permission Permissions (string filename)
 
 
static string ReadLink (string fileName)
 
 
static bool Remove (string fileName)
 
 
static bool Rename (string oldName, string newName)
 
 
static bool Resize (string filename, long sz)
 
 
static void SetDecodingFunction (Qt.FuncStringQByteArray arg1)
 
 
static void SetEncodingFunction (Qt.FuncQByteArrayString arg1)
 
 
static bool SetPermissions (string filename, QFile.Permission permissionSpec)
 
 
static string SymLinkTarget (string fileName)
 
 
static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QIODevice
static string Tr (string s, string c=null)
 
static string Tr (string s, string c, int n)
 
static string TrUtf8 (string s, string c=null)
 
static string TrUtf8 (string s, string c, int n)
 
- Static Public Member Functions inherited from QtCore.QObject
static bool Connect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod method, Qt.ConnectionType type=Qt.ConnectionType.AutoConnection)
 
 
static bool Connect (QObject sender, string signal, QObject receiver, string member, Qt.ConnectionType arg5=Qt.ConnectionType.AutoConnection)
 
 
static bool Disconnect (QObject sender, QMetaMethod signal, QObject receiver, QMetaMethod member)
 
 
static bool Disconnect (QObject sender, string signal, QObject receiver, string member)
 
 
static uint RegisterUserData ()
 
static string Tr (string s, string c=null)
 
 
static string Tr (string s, string c, int n)
 
 
static string TrUtf8 (string s, string c=null)
 
 
static string TrUtf8 (string s, string c, int n)
 
 
- Static Public Member Functions inherited from QtCore.Qt
static QDataStream Write (QDataStream s, object p)
 
static QDataStream Write (QDataStream arg1, QSizeF arg2)
 
static QTextStream Write (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Write (QDataStream arg1, QPoint arg2)
 
static QDataStream Write (QDataStream arg1, QLineF arg2)
 
static QDataStream Write (QDataStream arg1, QPointF arg2)
 
static QDataStream Write (QDataStream arg1, QChar arg2)
 
static QDataStream Write (QDataStream arg1, QByteArray arg2)
 
static QDataStream Write (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Write (QDataStream arg1, QRectF arg2)
 
static QDataStream Write (QDataStream arg1, QDateTime arg2)
 
static QDataStream Write (QDataStream arg1, QUrl arg2)
 
static QDataStream Write (QDataStream arg1, QTime arg2)
 
static QDataStream Write (QDataStream arg1, QLocale arg2)
 
static QDataStream Write (QDataStream arg1, QBitArray arg2)
 
static QDataStream Write (QDataStream arg1, QUuid arg2)
 
static QDataStream Write (QDataStream arg1, QLine arg2)
 
static QDataStream Write (QDataStream arg1, QDate arg2)
 
static QDataStream Write (QDataStream @out, QRegExp regExp)
 
static QDataStream Write (QDataStream arg1, QRect arg2)
 
static QDataStream Write (QDataStream arg1, QSize arg2)
 
static QDataStream Write (QDataStream s, QVariant.Type p)
 
static QDataStream Write (QDataStream arg1, string arg2)
 
static QDataStream Write (QDataStream @out, System.Collections.Generic.List< string > list)
 
static QDataStream Read (QDataStream arg1, QChar arg2)
 
static QDataStream Read (QDataStream arg1, QLocale arg2)
 
static QDataStream Read (QDataStream arg1, QRect arg2)
 
static QDataStream Read (QDataStream arg1, QEasingCurve arg2)
 
static QDataStream Read (QDataStream arg1, QDate arg2)
 
static QDataStream Read (QDataStream arg1, QUrl arg2)
 
static QDataStream Read (QDataStream arg1, QUuid arg2)
 
static QTextStream Read (QTextStream s, Qt.FuncQTextStreamQTextStream f)
 
static QDataStream Read (QDataStream arg1, QLineF arg2)
 
static QDataStream Read (QDataStream arg1, QRectF arg2)
 
static QDataStream Read (QDataStream arg1, QPointF arg2)
 
static QDataStream Read (QDataStream arg1, QLine arg2)
 
static QDataStream Read (QDataStream arg1, QBitArray arg2)
 
static QDataStream Read (QDataStream arg1, QSize arg2)
 
static QDataStream Read (QDataStream arg1, QDateTime arg2)
 
static QDataStream Read (QDataStream arg1, QTime arg2)
 
static QDataStream Read (QDataStream arg1, QPoint arg2)
 
static QDataStream Read (QDataStream @in, QRegExp regExp)
 
static QDataStream Read (QDataStream s, object p)
 
static QDataStream Read (QDataStream arg1, QByteArray arg2)
 
static QDataStream Read (QDataStream arg1, QSizeF arg2)
 
static QDataStream Read (QDataStream arg1, string arg2)
 
static QDataStream Read (QDataStream s, QVariant.Type p)
 
static QDataStream Read (QDataStream @in, System.Collections.Generic.List< string > list)
 
static double qAcos (double v)
 
static void qAddPostRoutine (System.Action arg1)
 
static string qAppName ()
 
static double qAsin (double v)
 
static double qAtan (double v)
 
static double qAtan2 (double x, double y)
 
static void qBadAlloc ()
 
static int qCeil (double v)
 
static ushort qChecksum (string s, uint len)
 
static QByteArray qCompress (QByteArray data)
 
static QByteArray qCompress (QByteArray data, int compressionLevel=-1)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes)
 
static QByteArray qCompress (Pointer< byte > data, int nbytes, int compressionLevel=-1)
 
static double qCos (double v)
 
static double qExp (double v)
 
static double qFabs (double v)
 
static double qFastCos (double x)
 
static double qFastSin (double x)
 
static string qFlagLocation (string method)
 
static int qFloor (double v)
 
static bool qFuzzyCompare (double p1, double p2)
 
static bool qFuzzyCompare (float p1, float p2)
 
static bool qFuzzyIsNull (double d)
 
static bool qFuzzyIsNull (float f)
 
static uint qHash (QBitArray key)
 
static uint qHash (QChar key)
 
static uint qHash (QStringRef key)
 
static uint qHash (QUrl url)
 
static uint qHash (QPersistentModelIndex index)
 
static uint qHash (QByteArray key)
 
static uint qHash (QModelIndex index)
 
static uint qHash (uint key)
 
static uint qHash (sbyte key)
 
static uint qHash (byte key)
 
static uint qHash (short key)
 
static uint qHash (NativeLong key)
 
static uint qHash (ushort key)
 
static uint qHash (long key)
 
static uint qHash (ulong key)
 
static uint qHash (int key)
 
static uint qHash (string key)
 
static uint qHash (NativeULong key)
 
static double qInf ()
 
static Qt.ActionQtMsgTypeString qInstallMsgHandler (Qt.ActionQtMsgTypeString arg1)
 
static int qIntCast (float f)
 
static int qIntCast (double f)
 
static bool qIsFinite (double d)
 
static bool qIsFinite (float f)
 
static bool qIsInf (float f)
 
static bool qIsInf (double d)
 
static bool qIsNaN (float f)
 
static bool qIsNaN (double d)
 
static bool qIsNull (float f)
 
static bool qIsNull (double d)
 
static double qLn (double v)
 
static double qPow (double x, double y)
 
static double qQNaN ()
 
static void qRegisterStaticPluginInstanceFunction (Qt.FuncQObject function)
 
static void qRemovePostRoutine (System.Action arg1)
 
static int qRound (double d)
 
static long qRound64 (double d)
 
static double qSNaN ()
 
static bool qSharedBuild ()
 
static double qSin (double v)
 
static double qSqrt (double v)
 
static bool qStringComparisonHelper (QStringRef s1, string s2)
 
static double qTan (double v)
 
static QByteArray qUncompress (QByteArray data)
 
static QByteArray qUncompress (Pointer< byte > data, int nbytes)
 
static string qVersion ()
 
static void Qbswap_helper (Pointer< byte > src, Pointer< byte > dest, int size)
 
static QByteArray Qgetenv (string varName)
 
static bool Qputenv (string varName, QByteArray value)
 
static int Qrand ()
 
static void Qsrand (uint seed)
 
static int Qstrcmp (QByteArray str1, QByteArray str2)
 
static int Qstrcmp (QByteArray str1, string str2)
 
static int Qstrcmp (string str1, QByteArray str2)
 
static int Qstrcmp (string str1, string str2)
 
static Pointer< sbyte > Qstrcpy (Pointer< sbyte > dst, string src)
 
static Pointer< sbyte > Qstrdup (string arg1)
 
static int Qstricmp (string arg1, string arg2)
 
static uint Qstrlen (string str)
 
static int Qstrncmp (string str1, string str2, uint len)
 
static Pointer< sbyte > Qstrncpy (Pointer< sbyte > dst, string src, uint len)
 
static int Qstrnicmp (string arg1, string arg2, uint len)
 
static uint Qstrnlen (string str, uint maxlen)
 
static string QtTrId (string id, int n=-1)
 

Protected Member Functions

 QFile (System.Type dummy)
 
override long ReadData (Pointer< sbyte > data, long maxlen)
 
 
override long ReadLineData (Pointer< sbyte > data, long maxlen)
 
 
override long WriteData (string data, long len)
 
 
- Protected Member Functions inherited from QtCore.QIODevice
 QIODevice (System.Type dummy)
 
new void OnAboutToClose ()
 
 
new void OnBytesWritten (long bytes)
 
 
new void OnReadChannelFinished ()
 
 
new void OnReadyRead ()
 
 
new void SetErrorString (string errorString)
 
 
new void SetOpenMode (QIODevice.OpenModeFlag openMode)
 
 
- Protected Member Functions inherited from QtCore.QObject
 QObject (System.Type dummy)
 
virtual void OnChildEvent (QChildEvent arg1)
 
 
virtual void ConnectNotify (string signal)
 
 
virtual void OnCustomEvent (QEvent arg1)
 
 
new void OnDestroyed (QObject arg1=null)
 
 
virtual void DisconnectNotify (string signal)
 
 
new int Receivers (string signal)
 
 
new QObject Sender ()
 
 
new int SenderSignalIndex ()
 
 
virtual void OnTimerEvent (QTimerEvent arg1)
 
 

Properties

new string FileName [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQFileSignals Emit [get]
 
- Properties inherited from QtCore.QIODevice
Slot ReadyRead
 
 
Slot< System.Int64 > BytesWritten
 
 
Slot AboutToClose
 
 
Slot ReadChannelFinished
 
 
static new QMetaObject StaticMetaObject [get]
 
new IQIODeviceSignals Emit [get]
 
- Properties inherited from QtCore.QObject
virtual EventHandler
< QEventArgs< QChildEvent > > 
ChildEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
CustomEvent
 
 
virtual EventHandler
< QEventArgs< QEvent > > 
Event
 
 
virtual EventHandler
< QEventArgs< QTimerEvent > > 
TimerEvent
 
 
Slot< QObjectDestroyedQObject
 
Slot Destroyed
 
 
new QObject Parent [get, set]
 
 
virtual System.IntPtr SmokeObject [get, set]
 
new string ObjectName [get, set]
 
 
static new QMetaObject StaticMetaObject [get]
 
 
static new QMetaObject StaticQtMetaObject [get]
 
new IQObjectSignals Emit [get]
 

Additional Inherited Members

- Protected Attributes inherited from QtCore.QObject
object Q_EMIT = null
 
SmokeInvocation interceptor
 
readonly List< QEventHandler > eventFilters = new List<QEventHandler>()
 

Detailed Description

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

QFile is an I/O device for reading and writing text and binary files and 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.

Reading Files Directly

The following example reads a text file line by line:

QFile file("in.txt");

if (!file.open(QIODevice::ReadOnly | QIODevice::Text))

return;

while (!file.atEnd()) {

QByteArray line = file.readLine();

process_line(line);

}

The QIODevice::Text flag passed to open() tells Qt to convert Windows-style line terminators ("\r\n") into C++-style terminators ("\n"). By default, QFile assumes binary, i.e. it doesn't perform any conversion on the bytes stored in the file.

Using Streams to Read Files

The next example uses QTextStream to read a text file line by line:

QFile file("in.txt");

if (!file.open(QIODevice::ReadOnly | QIODevice::Text))

return;

QTextStream in(&file);

while (!in.atEnd()) {

QString line = in.readLine();

process_line(line);

}

QTextStream takes care of converting the 8-bit data stored on disk into a 16-bit Unicode QString. By default, it assumes that the user system's local 8-bit encoding is used (e.g., ISO 8859-1 for most of Europe; see QTextCodec::codecForLocale() for details). This can be changed using setCodec().

To write text, we can use operator<<(), which is overloaded to take a QTextStream on the left and various data types (including QString) on the right:

QFile file("out.txt");

if (!file.open(QIODevice::WriteOnly | QIODevice::Text))

return;

QTextStream out(&file);

out << "The magic number is: " << 49 << "\n";

QDataStream is similar, in that you can use operator<<() to write data and operator>>() to read it back. See the class documentation for details.

When you use QFile, QFileInfo, and QDir to access the file system with Qt, you can use Unicode file names. On Unix, these file names are converted to an 8-bit encoding. If you want to use standard C++ APIs (<cstdio> or <iostream>) or platform-specific APIs to access files instead of QFile, you can use the encodeName() and decodeName() functions to convert between Unicode file names and 8-bit file names.

On Unix, there are some special system files (e.g. in /proc) for which size() will always return 0, yet you may still be able to read more data from such a file; the data is generated in direct response to you calling read(). In this case, however, you cannot use atEnd() to determine if there is more data to read (since atEnd() will return true for a file that claims to have size 0). Instead, you should either call readAll(), or call read() or readLine() repeatedly until no more data can be read. The next example uses QTextStream to read /proc/modules line by line:

QFile file("/proc/modules");

if (!file.open(QIODevice::ReadOnly | QIODevice::Text))

return;

QTextStream in(&file);

QString line = in.readLine();

while (!line.isNull()) {

process_line(line);

line = in.readLine();

}

Signals

Unlike other QIODevice implementations, such as QTcpSocket, QFile does not emit the aboutToClose(), bytesWritten(), or readyRead() signals. This implementation detail means that QFile is not suitable for reading and writing certain types of files, such as device files on Unix platforms.

Platform Specific Issues

File permissions are handled differently on Linux/Mac OS X and Windows. In a non writable directory on Linux, files cannot be created. This is not always the case on Windows, where, for instance, the 'My Documents' directory usually is not writable, but it is still possible to create files in it.

See also QTextStream, QDataStream, QFileInfo, QDir, and The Qt Resource System.

Member Enumeration Documentation

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

Enumerator:
AbortError 

The operation was aborted.

CopyError 

The file could not be copied.

FatalError 

A fatal error occurred.

NoError 

No error occurred.

OpenError 

The file could not be opened.

PermissionsError 

The file could not be accessed.

PositionError 

The position in the file could not be changed.

ReadError 

An error occurred when reading from the file.

RemoveError 

The file could not be removed.

RenameError 

The file could not be renamed.

ResizeError 

The file could not be resized.

ResourceError 
TimeOutError 

A timeout occurred.

UnspecifiedError 

An unspecified error occurred.

WriteError 

An error occurred when writing to the file.

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

This enum was introduced or modified in Qt 4.8.

Enumerator:
AutoCloseHandle 

The file handle passed into open() should be closed by close(), the default behaviour 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.

DontCloseHandle 

The file handle passed into open() will not be closed by Qt. The application must ensure that close() is called.

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

This enum was introduced or modified in Qt 4.4.

Enumerator:
NoOptions 

No options.

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.

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 that Qt does not by default check for permissions on NTFS file systems, as this may decrease the performance of file handling considerably. It is possible to force permission checking on NTFS by including the following code in your source:

extern Q_CORE_EXPORT int qt_ntfs_permission_lookup;

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

qt_ntfs_permission_lookup++; // turn checking on

qt_ntfs_permission_lookup–; // turn it off again

Enumerator:
ExeGroup 

The file is executable by the group.

ExeOther 

The file is executable by anyone.

ExeOwner 

The file is executable by the owner of the file.

ExeUser 

The file is executable by the user.

ReadGroup 

The file is readable by the group.

ReadOther 

The file is readable by anyone.

ReadOwner 

The file is readable by the owner of the file.

ReadUser 

The file is readable by the user.

WriteGroup 

The file is writable by the group.

WriteOther 

The file is writable by anyone.

WriteOwner 

The file is writable by the owner of the file.

WriteUser 

The file is writable by the user.

Constructor & Destructor Documentation

QtCore.QFile.QFile ( System.Type  dummy)
protected
QtCore.QFile.QFile ( )

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

QtCore.QFile.QFile ( QObject  parent)

Constructs a new file object with the given parent.

QtCore.QFile.QFile ( string  name)

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

QtCore.QFile.QFile ( string  name,
QObject  parent 
)

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

Member Function Documentation

override bool QtCore.QFile.AtEnd ( )
virtual

Reimplemented from QIODevice::atEnd().

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 QtCore.QIODevice.

override void QtCore.QFile.Close ( )
virtual

Reimplemented from QIODevice::close().

Calls QFile::flush() and closes the file. Errors from flush are ignored.

See also QIODevice::close().

Reimplemented from QtCore.QIODevice.

new bool QtCore.QFile.Copy ( string  newName)

Copies the file currently specified by fileName() to a file called newName. Returns true if successful; otherwise returns false.

Note that if a file with the name newName already exists, copy() returns false (i.e. QFile will not overwrite it).

The source file is closed before it is copied.

See also setFileName().

static bool QtCore.QFile.Copy ( string  fileName,
string  newName 
)
static

This is an overloaded function.

Copies the file fileName to newName. Returns true if successful; otherwise returns false.

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

See also rename().

override void QtCore.QFile.CreateProxy ( )
virtual

Reimplemented from QtCore.QObject.

Reimplemented in QtCore.QTemporaryFile.

static string QtCore.QFile.DecodeName ( QByteArray  localFileName)
static

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

See also setDecodingFunction() and encodeName().

static string QtCore.QFile.DecodeName ( string  localFileName)
static

This is an overloaded function.

Returns the Unicode version of the given localFileName. See encodeName() for details.

new void QtCore.QFile.Dispose ( )
static QByteArray QtCore.QFile.EncodeName ( string  fileName)
static

By default, this function 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() and setEncodingFunction().

new QFile.FileError QtCore.QFile.Error ( )

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().

new bool QtCore.QFile.Exists ( )

This is an overloaded function.

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

See also fileName() and setFileName().

static bool QtCore.QFile.Exists ( string  fileName)
static

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

virtual QAbstractFileEngine QtCore.QFile.FileEngine ( )
virtual

Reimplemented in QtCore.QTemporaryFile.

new bool QtCore.QFile.Flush ( )

Flushes any buffered data to the file. Returns true if successful; otherwise returns false.

new int QtCore.QFile.Handle ( )

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.

This function is not supported on Windows CE.

On Symbian, this function returns -1 if the file was opened normally, as Symbian OS native file handles do not fit in an int, and are incompatible with C library functions that the handle would be used for. If the file was opened using the overloads that take an open C library file handle / file descriptor, then this function returns that same handle.

See also QSocketNotifier.

override bool QtCore.QFile.IsSequential ( )
virtual

Reimplemented from QIODevice::isSequential().

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 QtCore.QIODevice.

new bool QtCore.QFile.Link ( string  newName)

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 error() to return RenameError.

Note: To create a valid link on Windows, linkName must have a .lnk file extension.

Note: Symbian filesystem does not support links.

See also setFileName().

static bool QtCore.QFile.Link ( string  oldname,
string  newName 
)
static

This is an overloaded function.

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().

new Pointer<byte> QtCore.QFile.Map ( long  offset,
long  size,
QFile.MemoryMapFlags  flags = QFile.MemoryMapFlags.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.

Any mapping options can be passed through flags.

Returns a pointer to the memory or 0 if there is an error.

Note: On Windows CE 5.0 the file will be closed before mapping occurs.

This function was introduced in Qt 4.4.

See also unmap() and QAbstractFileEngine::supportsExtension().

override bool QtCore.QFile.Open ( QIODevice.OpenModeFlag  flags)
virtual

Reimplemented from QIODevice::open().

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 WriteOnly or ReadWrite mode, if the relevant file does not already exist, this function will try to create a new file before opening it.

See also QIODevice::OpenMode and setFileName().

Reimplemented from QtCore.QIODevice.

Reimplemented in QtCore.QTemporaryFile.

new bool QtCore.QFile.Open ( int  fd,
QIODevice.OpenModeFlag  flags 
)

Reimplemented from QIODevice::open().

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 WriteOnly or ReadWrite mode, if the relevant file does not already exist, this function will try to create a new file before opening it.

See also QIODevice::OpenMode and setFileName().

new bool QtCore.QFile.Open ( int  fd,
QIODevice.OpenModeFlag  ioFlags,
QFile.FileHandleFlag  handleFlags 
)

Reimplemented from QIODevice::open().

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 WriteOnly or ReadWrite mode, if the relevant file does not already exist, this function will try to create a new file before opening it.

See also QIODevice::OpenMode and setFileName().

new QFile.Permission QtCore.QFile.Permissions ( )

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

See also setPermissions() and setFileName().

static QFile.Permission QtCore.QFile.Permissions ( string  filename)
static

This is an overloaded function.

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

override long QtCore.QFile.Pos ( )
virtual

Reimplemented from QIODevice::pos().

Reimplemented from QtCore.QIODevice.

override long QtCore.QFile.ReadData ( Pointer< sbyte >  data,
long  maxlen 
)
protectedvirtual

Reimplemented from QIODevice::readData().

Implements QtCore.QIODevice.

override long QtCore.QFile.ReadLineData ( Pointer< sbyte >  data,
long  maxlen 
)
protectedvirtual

Reimplemented from QIODevice::readLineData().

Reimplemented from QtCore.QIODevice.

new string QtCore.QFile.ReadLink ( )

Use symLinkTarget() instead.

static string QtCore.QFile.ReadLink ( string  fileName)
static

Use symLinkTarget() instead.

new bool QtCore.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().

static bool QtCore.QFile.Remove ( string  fileName)
static

This is an overloaded function.

Removes the file specified by the fileName given.

Returns true if successful; otherwise returns false.

See also remove().

new bool QtCore.QFile.Rename ( string  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.

See also setFileName().

static bool QtCore.QFile.Rename ( string  oldName,
string  newName 
)
static

This is an overloaded function.

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().

new bool QtCore.QFile.Resize ( long  sz)

Sets the file size (in bytes) sz. Returns true if the file 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.

See also size() and setFileName().

static bool QtCore.QFile.Resize ( string  filename,
long  sz 
)
static

Sets the file size (in bytes) sz. Returns true if the file 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.

See also size() and setFileName().

override bool QtCore.QFile.Seek ( long  offset)
virtual

Reimplemented from QIODevice::seek().

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() shall not immediately extend the file. If a write is performed at this position, then the file shall 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 QtCore.QIODevice.

static void QtCore.QFile.SetDecodingFunction ( Qt.FuncStringQByteArray  arg1)
static

Sets the function for decoding 8-bit file names. The default uses the locale-specific 8-bit encoding.

Warning: This function is not reentrant.

See also setEncodingFunction() and decodeName().

static void QtCore.QFile.SetEncodingFunction ( Qt.FuncQByteArrayString  arg1)
static

Sets the function for encoding Unicode file names. The default encodes in the locale-specific 8-bit encoding.

Warning: This function is not reentrant.

See also encodeName() and setDecodingFunction().

new bool QtCore.QFile.SetPermissions ( QFile.Permission  permissionSpec)

Sets the permissions for the file to the permissions specified. Returns true if successful, or false if the permissions cannot be modified.

See also permissions() and setFileName().

static bool QtCore.QFile.SetPermissions ( string  filename,
QFile.Permission  permissionSpec 
)
static

Sets the permissions for the file to the permissions specified. Returns true if successful, or false if the permissions cannot be modified.

See also permissions() and setFileName().

override long QtCore.QFile.Size ( )
virtual

Reimplemented from QIODevice::size().

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 QtCore.QIODevice.

new string QtCore.QFile.SymLinkTarget ( )

This is an overloaded function.

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.

This function was introduced in Qt 4.2.

See also fileName() and setFileName().

static string QtCore.QFile.SymLinkTarget ( string  fileName)
static

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.

This function was introduced in Qt 4.2.

static string QtCore.QFile.Tr ( string  s,
string  c = null 
)
static
static string QtCore.QFile.Tr ( string  s,
string  c,
int  n 
)
static
static string QtCore.QFile.TrUtf8 ( string  s,
string  c = null 
)
static
static string QtCore.QFile.TrUtf8 ( string  s,
string  c,
int  n 
)
static
new bool QtCore.QFile.Unmap ( Pointer< byte >  address)

Unmaps the memory address.

Returns true if the unmap succeeds; false otherwise.

This function was introduced in Qt 4.4.

See also map() and QAbstractFileEngine::supportsExtension().

new void QtCore.QFile.UnsetError ( )

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

See also error().

override long QtCore.QFile.WriteData ( string  data,
long  len 
)
protectedvirtual

Reimplemented from QIODevice::writeData().

Implements QtCore.QIODevice.

Property Documentation

new IQFileSignals QtCore.QFile.Emit
getprotected
new string QtCore.QFile.FileName
getset

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

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:

QFile file;

QDir::setCurrent("/tmp");

file.setFileName("readme.txt");

QDir::setCurrent("/home");

file.open(QIODevice::ReadOnly); // opens "/home/readme.txt" under Unix

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

new QMetaObject QtCore.QFile.StaticMetaObject
staticget