QIODevice Class Reference |
Constant | Value | Description |
---|---|---|
QIODevice::NotOpen | 0x0000 | The device is not open. |
QIODevice::ReadOnly | 0x0001 | The device is open for reading. |
QIODevice::WriteOnly | 0x0002 | The device is open for writing. |
QIODevice::ReadWrite | ReadOnly | WriteOnly | The device is open for reading and writing. |
QIODevice::Append | 0x0004 | The device is opened in append mode, so that all data is written to the end of the file. |
QIODevice::Truncate | 0x0008 | If possible, the device is truncated before it is opened. All earlier contents of the device are lost. |
QIODevice::Text | 0x0010 | When reading, the end-of-line terminators are translated to '\n'. When writing, the end-of-line terminators are translated to the local encoding, for example '\r\n' for Win32. |
QIODevice::Unbuffered | 0x0020 | Any buffer in the device is bypassed. |
Certain flags, such as QIODevice::Unbuffered and QIODevice::Truncate, might be meaningless for some subclasses. (For example, access to a QBuffer is always unbuffered.)
The OpenMode type is a typedef for QFlags<OpenModeFlag>. It stores an OR combination of OpenModeFlag values.
Constructs a QIODevice object.
Constructs a QIODevice object with the given parent.
Destructs the QIODevice object.
This signal is emitted when the device is about to close. Connect this signal if you have operations that need to be performed before the device closes (e.g., if you have data in a separate buffer that needs to be written to the device).
Returns true if the current read and write position is at the end of the device (i.e. there is no more data available for reading on the device); otherwise returns false.
For some devices, atEnd() can return true even though there is more data to read. This special case only applies to devices that generate data in direct response to you calling read() (e.g., /dev or /proc files on Unix and Mac OS X, or console input / stdin on all platforms).
See also bytesAvailable(), read(), and isSequential().
Returns the number of bytes that are available for reading. This function is commonly used with sequential devices to determine the number of bytes to allocate in a buffer before reading.
Subclasses that reimplement this function call the base implementation in order to include the size of the unget buffer.
For buffered devices, this function returns the number of bytes waiting to be written. For devices with no buffer, this function returns 0.
This signal is emitted every time a payload of data has been written to the device. The bytes argument is set to the number of bytes that were written in this payload.
bytesWritten() is not emitted recursively; if you reenter the event loop or call waitForBytesWritten() inside a slot connected to the bytesWritten() signal, the signal will not be reemitted (although waitForBytesWritten() may still return true).
See also readyRead().
Returns true if a complete line of data can be read from the device; otherwise returns false.
Note that unbuffered devices, which have no way of determining what can be read, always return false.
This function is often called in conjunction with the readyRead() signal.
See also readyRead() and readLine().
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen. The error string is also reset.
See also setOpenMode() and OpenMode.
Returns a human-readable description of the last device error that occurred.
See also setErrorString().
Reads one character from the device and stores it in c. If c is 0, the character is discarded. Returns true on success; otherwise returns false.
See also read(), putChar(), and ungetChar().
Returns true if the device is open; otherwise returns false. A device is open if it can be read from and/or written to. By default, this function returns false if openMode() returns NotOpen.
See also openMode() and OpenMode.
Returns true if data can be read from the device; otherwise returns false. Use bytesAvailable() to determine how many bytes can be read.
This is a convenience function which checks if the OpenMode of the device contains the ReadOnly flag.
See also openMode() and OpenMode.
Returns true if this device is sequential; otherwise returns false.
Sequential devices, as opposed to a random-access devices, have no concept of a start, an end, a size, or a current position, and they do not support seeking. You can only read from the device when it reports that data is available. The most common example of a sequential device is a network socket. On Unix, special files such as /dev/zero and fifo pipes are sequential.
Regular files, on the other hand, do support random access. They have both a size and a current position, and they also support seeking backwards and forwards in the data stream. Regular files are non-sequential.
See also bytesAvailable().
Returns true if the Text flag is enabled; otherwise returns false.
See also setTextModeEnabled().
Returns true if data can be written to the device; otherwise returns false.
This is a convenience function which checks if the OpenMode of the device contains the WriteOnly flag.
See also openMode() and OpenMode.
Opens the device and sets its OpenMode to mode.
See also openMode() and OpenMode.
Returns the mode in which the device has been opened; i.e. ReadOnly or WriteOnly.
See also setOpenMode() and OpenMode.
Reads at most maxSize bytes from the device into data, without side effects (i.e., if you call read() after peek(), you will get the same data). Returns the number of bytes read. If an error occurs, such as when attempting to peek a device opened in WriteOnly mode, this function returns -1.
0 is returned when no more data is available for reading.
Example:
bool isExeFile(QFile *file) { char buf[2]; if (file->peek(buf, sizeof(buf)) == sizeof(buf)) return (buf[0] == 'M' && buf[1] == 'Z'); return false; }
This function was introduced in Qt 4.1.
See also read().
This is an overloaded member function, provided for convenience.
Peeks at most maxSize bytes from the device, returning the data peeked as a QByteArray.
Example:
bool isExeFile(QFile *file) { return file->peek(2) == "MZ"; }
This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for peeking, or that an error occurred.
This function was introduced in Qt 4.1.
See also read().
For random-access devices, this function returns the position that data is written to or read from. For sequential devices or closed devices, where there is no concept of a "current position", 0 is returned.
See also isSequential() and seek().
Writes the character c to the device. Returns true on success; otherwise returns false.
See also write(), getChar(), and ungetChar().
Reads at most maxSize bytes from the device into data, and returns the number of bytes read. If an error occurs, such as when attempting to read from a device opened in WriteOnly mode, this function returns -1.
0 is returned when no more data is available for reading.
See also readData(), readLine(), and write().
This is an overloaded member function, provided for convenience.
Reads at most maxSize bytes from the device, and returns the data read as a QByteArray.
This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.
Reads all available data from the device, and returns it as a QByteArray.
This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an error occurred.
This function is called by QIODevice. Reimplement this function when creating a subclass of QIODevice.
See also read(), readLine(), and writeData().
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. If an error occurred, -1 is returned.
A terminating '\0' byte is always appended to data, so maxSize must be larger than 1.
Data is read until either of the following conditions are met:
For example, the following code reads a line of characters from a file:
QFile file("box.txt"); if (file.open(QFile::ReadOnly)) { char buf[1024]; qint64 lineLength = file.readLine(buf, sizeof(buf)); if (lineLength != -1) { // the line is available in buf } }
If the '\n' character is the 1023th character read then it will be inserted into the buffer; if it occurs after the 1023 character then it is not read.
This function calls readLineData(), which is implemented using repeated calls to getChar(). You can provide a more efficient implementation by reimplementing readLineData() in your own subclass.
See also getChar(), read(), and write().
This is an overloaded member function, provided for convenience.
Reads a line from the device, but no more than maxSize characters, and returns the result as a QByteArray.
This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.
Reads up to maxSize characters into data and returns the number of characters read.
This function is called by readLine(), and provides its base implementation, using getChar(). Buffered devices can improve the performance of readLine() by reimplementing this function.
readLine() appends a '\0' byte to data; readLineData() does not need to do this.
This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your device.
readyRead() is not emitted recursively; if you reenter the event loop or call waitForReadyRead() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although waitForReadyRead() may still return true).
See also bytesWritten().
Seeks to the start of input for random-access devices. Returns true on success; otherwise returns false (for example, if the device is not open).
See also 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.
When subclassing QIODevice, you must call QIODevice::seek() at the start of your function to ensure integrity with QIODevice's built-in ungetbuffer. The base implementation always returns true.
See also pos().
Sets the human readable description of the last device error that occurred to str.
See also errorString().
Sets the OpenMode of the device to openMode. Reimplement this function to set the open mode when reimplementing open().
See also openMode() and OpenMode.
If enabled is true, this function sets the Text flag on the device; otherwise the Text flag is removed. This feature is useful for classes that provide custom end-of-line handling on a QIODevice.
See also isTextModeEnabled(), open(), and setOpenMode().
For open random-access devices, this function returns the size of the device. For open sequential devices, bytesAvailable() is returned.
If the device is closed, the size returned will not reflect the actual size of the device.
Puts the character c back into the device, and decrements the current position unless the position is 0. This function is usually called to "undo" a getChar() operation, such as when writing a backtracking parser.
If c was not previously read from the device, the behavior is undefined.
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. If msecs is -1, this function will not time out. For unbuffered devices, it returns immediately.
Returns true if a payload of data was written to the device; otherwise returns false (i.e. if the operation timed out, or if an error occurred).
This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.
If called from within a slot connected to the bytesWritten() signal, bytesWritten() will not be reemitted.
Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.
See also waitForReadyRead().
Blocks until data is available for reading and the readyRead() signal has been emitted, or until msecs milliseconds have passed. If msecs is -1, this function will not time out.
Returns true if data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).
This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.
If called from within a slot connected to the readyRead() signal, readyRead() will not be reemitted.
Warning: Calling this function from the main (GUI) thread might cause your user interface to freeze.
See also waitForBytesWritten().
Writes at most maxSize bytes of data from data to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.
See also read() and writeData().
This is an overloaded member function, provided for convenience.
Writes the content of byteArray to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.
See also read() and writeData().
Writes up to maxSize bytes from data to the device. Returns the number of bytes written, or -1 if an error occurred.
This function is called by QIODevice. Reimplement this function when creating a subclass of QIODevice.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.1 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com