QFile Class Reference
|
Константа | Значение | Описание |
---|---|---|
QFile::NoError | 0 | No error occurred. |
QFile::ReadError | 1 | An error occurred when reading from the file. |
QFile::WriteError | 2 | An error occurred when writing to the file. |
QFile::FatalError | 3 | A fatal error occurred. |
QFile::ResourceError | 4 | |
QFile::OpenError | 5 | The file could not be opened. |
QFile::AbortError | 6 | The operation was aborted. |
QFile::TimeOutError | 7 | A timeout occurred. |
QFile::UnspecifiedError | 8 | An unspecified error occurred. |
QFile::RemoveError | 9 | The file could not be removed. |
QFile::RenameError | 10 | The file could not be renamed. |
QFile::PositionError | 11 | The position in the file could not be changed. |
QFile::ResizeError | 12 | The file could not be resized. |
QFile::PermissionsError | 13 | The file could not be accessed. |
QFile::CopyError | 14 | The file could not be copied. |
This enum describes special options that may be used by the map() function.
Константа | Значение | Описание |
---|---|---|
QFile::NoOptions | 0 | No options. |
Данное перечисление было введено в Qt 4.4.
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.
Константа | Значение | Описание |
---|---|---|
QFile::ReadOwner | 0x4000 | The file is readable by the owner of the file. |
QFile::WriteOwner | 0x2000 | The file is writable by the owner of the file. |
QFile::ExeOwner | 0x1000 | The file is executable by the owner of the file. |
QFile::ReadUser | 0x0400 | The file is readable by the user. |
QFile::WriteUser | 0x0200 | The file is writable by the user. |
QFile::ExeUser | 0x0100 | The file is executable by the user. |
QFile::ReadGroup | 0x0040 | The file is readable by the group. |
QFile::WriteGroup | 0x0020 | The file is writable by the group. |
QFile::ExeGroup | 0x0010 | The file is executable by the group. |
QFile::ReadOther | 0x0004 | The file is readable by anyone. |
QFile::WriteOther | 0x0002 | The file is writable by anyone. |
QFile::ExeOther | 0x0001 | The file is executable by anyone. |
Warning: Because of differences in the platforms supported by Qt, the semantics of ReadUser, WriteUser and ExeUser are platform-dependent: On Unix, the rights of the owner of the file are returned and on Windows the rights of the current user are returned. This behavior might change in a future Qt version.
The Permissions type is a typedef for QFlags<Permission>. It stores an OR combination of Permission values.
Use QFile::Permission instead.
Constructs a new file object to represent the file with the given name.
Constructs a new file object with the given parent.
Constructs a new file object with the given parent to represent the file with the specified name.
Destroys the file object, closing it if necessary.
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.
Переопределено из QIODevice.
Copies the file currently specified by fileName() to a file called newName. Возвращает true в случае успеха; при неудаче возвращается 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.
Смотрите также setFileName().
Это перегруженная функция, предоставленная для удобства.
Copies the file fileName to newName. Возвращает true в случае успеха; при неудаче возвращается false.
If a file with the name newName already exists, copy() returns false (i.e., QFile will not overwrite it).
See also rename().
This does the reverse of QFile::encodeName() using localFileName.
See also setDecodingFunction() and encodeName().
Это перегруженная функция, предоставленная для удобства.
Returns the Unicode version of the given localFileName. See encodeName() for details.
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().
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().
Returns true if the file specified by fileName exists; otherwise returns false.
Это перегруженная функция, предоставленная для удобства.
Returns true if the file specified by fileName() exists; otherwise returns false.
Смотрите также fileName() и setFileName().
Returns the name set by setFileName() or to the QFile constructors.
See also setFileName() and QFileInfo::fileName().
Flushes any buffered data to the file. Возвращает true в случае успеха; при неудаче возвращается false.
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.
See also QSocketNotifier.
Returns true if the file can only be manipulated sequentially; otherwise returns false.
Most files support random-access, but some special files may not.
Переопределено из QIODevice.
See also QIODevice::isSequential().
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). Возвращает true в случае успеха; при неудаче возвращается 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.
Смотрите также setFileName().
Это перегруженная функция, предоставленная для удобства.
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). Возвращает true в случае успеха; при неудаче возвращается false.
See also link().
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.
Эта функция была введена в Qt 4.4.
See also unmap() and QAbstractFileEngine::supportsExtension().
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.
Note: Because of limitations in the native API, QFile ignores the Unbuffered flag on Windows.
Переопределено из QIODevice.
See also QIODevice::OpenMode and setFileName().
Это перегруженная функция, предоставленная для удобства.
Opens the existing file handle fh in the given mode. Возвращает true в случае успеха; при неудаче возвращается false.
Пример:
#include <stdio.h>
void printError(const char* msg)
{
QFile file;
file.open(stderr, QIODevice::WriteOnly);
file.write(msg, qstrlen(msg)); // write to stderr
file.close();
}
When a QFile is opened using this function, close() does not actually close the file, but only flushes it.
Предупреждение:
Note: For Windows CE you may not be able to call seek() and resize(). Also, size() is set to 0.
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
See also close() and qmake Variable Reference.
Это перегруженная функция, предоставленная для удобства.
Opens the existing file descripter fd in the given mode. Возвращает true в случае успеха; при неудаче возвращается false.
When a QFile is opened using this function, close() does not actually close the file.
The QFile that is opened using this function is automatically set to be in raw mode; this means that the file input/output functions are slow. If you run into performance issues, you should try to use one of the other open functions.
Warning: If fd is 0 (stdin), 1 (stdout), or 2 (stderr), you may not be able to seek(). size() is set to LLONG_MAX (in <climits>).
Warning: For Windows CE you may not be able to call seek(), setSize(), fileTime(). size() is set to 0.
Warning: Since this function opens the file without specifying the file name, you cannot use this QFile with a QFileInfo.
Смотрите также close().
Returns the complete OR-ed together combination of QFile::Permission for the file.
See also setPermissions() and setFileName().
Это перегруженная функция, предоставленная для удобства.
Returns the complete OR-ed together combination of QFile::Permission for fileName.
Removes the file specified by fileName(). Возвращает true в случае успеха; при неудаче возвращается false.
The file is closed before it is removed.
Смотрите также setFileName().
Это перегруженная функция, предоставленная для удобства.
Removes the file specified by the fileName given.
Возвращает true в случае успеха; при неудаче возвращается false.
See also remove().
Renames the file currently specified by fileName() to newName. Возвращает true в случае успеха; при неудаче возвращается 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.
Смотрите также setFileName().
Это перегруженная функция, предоставленная для удобства.
Renames the file oldName to newName. Возвращает true в случае успеха; при неудаче возвращается false.
If a file with the name newName already exists, rename() returns false (i.e., QFile will not overwrite it).
See also rename().
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().
Это перегруженная функция, предоставленная для удобства.
Sets fileName to size (in bytes) sz. Returns true if the file 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.
Смотрите также resize().
Sets the function for decoding 8-bit file names. The default uses the locale-specific 8-bit encoding.
Предупреждение: Данная функция не является реентерабельной.
See also setEncodingFunction() and decodeName().
Sets the function for encoding Unicode file names. The default encodes in the locale-specific 8-bit encoding.
Предупреждение: Данная функция не является реентерабельной.
See also encodeName() and setDecodingFunction().
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.
Пример:
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.
See also fileName(), QFileInfo, and QDir.
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().
Это перегруженная функция, предоставленная для удобства.
Sets the permissions for fileName file to permissions.
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().
Переопределено из QIODevice.
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.
Эта функция была введена в Qt 4.2.
Это перегруженная функция, предоставленная для удобства.
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.
Эта функция была введена в Qt 4.2.
Смотрите также fileName() и setFileName().
Unmaps the memory address.
Returns true if the unmap succeeds; false otherwise.
Эта функция была введена в Qt 4.4.
See also map() and QAbstractFileEngine::supportsExtension().
Sets the file's error to QFile::NoError.
Смотрите также error().
Copyright © 2008 Nokia | Торговые марки | Qt 4.4.3 |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |