The QIODevice class is the base class of I/O devices. More...
#include <qiodevice.h>
Inherited by QBuffer and QFile.
An I/O device represents a medium that one can read bytes from and write bytes to. The QIODevice class itself is not capable of reading or writing any data; it has virtual functions for doing so. These functions are implemented by the subclasses QFile and QBuffer.
There are two types of I/O devices;
<em>direct access</em> and
<em>sequential access </em> devices.
Files can normally be accessed
directly, except stdin
etc., which must be processed sequentially.
Buffers are always direct access devices.
The access mode of an I/O device can be either raw or buffered. QFile objects can be created using one of these. Raw access mode is more low level, while buffered access use smart buffering techniques. The raw access mode is best when I/O is block-operated using 4kB block size or greater. Buffered access works better when reading small portions of data at a time.
An I/O device operation can be executed in either synchronous or asynchronous mode. The I/O devices currently supported by Qt only execute synchronously.
The QDataStream and QTextStream provide binary and text operations on QIODevice objects.
QIODevice provides numerous pure virtual functions you need to implement when subclassing it. Here is a skeleton subclass:
class YourDevice : public QIODevice { public: YourDevice(); ~YourDevice(); bool open( int mode ); void close(); void flush(); uint size() const; int at() const; // not a pure virtual function bool at( int ); // not a pure virtual function bool atEnd() const; // not a pure virtual function int readBlock( char *data, uint len ); int writeBlock( const char *data, uint len ); int readLine( char *data, uint maxlen ); int getch(); int putch( int ); int ungetch( int ); };
The three non-pure virtual functions can be ignored if your device is sequential (e.g. a tape device).
See also: QDataStream and QTextStream.
Constructs an I/O device.
[virtual]
Destroys the I/O device.
[virtual]
Virtual function that sets the I/O device index to pos.
See also: size().
Reimplemented in QBuffer and QFile.
[virtual]
Virtual function that returns the current I/O device index.
This index is the data read/write head of the I/O device.
See also: size().
Reimplemented in QBuffer and QFile.
[virtual]
Virtual function that returns TRUE if the I/O device index is at the end of the input.
Reimplemented in QFile.
[virtual]
Closes the I/O device.
This virtual function must be reimplemented by all subclasses.
See also: open().
Reimplemented in QBuffer and QFile.
Returns the current I/O device flags setting.
Flags consists of mode flags and state flags.
[virtual]
Flushes an open I/O device.
This virtual function must be reimplemented by all subclasses.
Reimplemented in QBuffer and QFile.
[virtual]
Reads a single byte/character from the I/O device.
Returns the byte/character read, or -1 if the end of the I/O device has been reached.
This virtual function must be reimplemented by all subclasses.
See also: putch() and ungetch().
Reimplemented in QBuffer and QFile.
Returns TRUE if the I/O device is a asynchronous device, otherwise FALSE.
This mode is currently not in use.
See also: isSynchronous().
Returns TRUE if the I/O device is a buffered (not raw) device, otherwise FALSE.
See also: isRaw().
Returns TRUE if the I/O device is a combined access (both direct and sequential) device, otherwise FALSE.
This access method is currently not in use.
Returns TRUE if the I/O device is a direct access (not sequential) device, otherwise FALSE.
See also: isSequentialAccess().
Returns TRUE if the I/O device state is 0, i.e. the device is not open.
See also: isOpen().
Returns TRUE if the I/O device state has been opened, otherwise FALSE.
See also: isInactive().
Returns TRUE if the I/O device is a raw (not buffered) device, otherwise FALSE.
See also: isBuffered().
Returns TRUE if the I/O device was opened using IO_ReadWrite
mode.
See also: isReadable() and isWritable().
Returns TRUE if the I/O device was opened using IO_ReadOnly
or
IO_ReadWrite
mode.
See also: isWritable() and isReadWrite().
Returns TRUE if the I/O device is a sequential access (not direct) device, otherwise FALSE. Operations involving size() and at(int) are not valid on sequential devices.
See also: isDirectAccess().
Returns TRUE if the I/O device is a synchronous device, otherwise FALSE.
See also: isAsynchronous().
Returns TRUE if the I/O device translates carriage-return and linefeed characters.
A QFile is translated if it is opened with the IO_Translate
mode
flag.
Returns TRUE if the I/O device was opened using IO_WriteOnly
or
IO_ReadWrite
mode.
See also: isReadable() and isReadWrite().
Returns bits OR'ed together that specify the current operation mode.
These are the flags that were given to the open() function.
The flags are: IO_ReadOnly, IO_WriteOnly, IO_ReadWrite, IO_Append, IO_Truncate
and IO_Translate.
[virtual]
Opens the I/O device using the specified mode. Returns TRUE if successful, or FALSE if the device could not be opened.
The mode parameter m must be a combination of the following flags.
IO_Raw
specified raw (unbuffered) file access.
IO_ReadOnly
opens a file in read-only mode.
IO_WriteOnly
opens a file in write-only mode.
IO_ReadWrite
opens a file in read/write mode.
IO_Append
sets the file index to the end of the file.
IO_Truncate
truncates the file.
IO_Translate
enables carriage returns and linefeed translation
for text files under MS-DOS, Window, OS/2 and Macintosh. Cannot be
combined with IO_Raw.
This virtual function must be reimplemented by all subclasses.
See also: close().
Reimplemented in QBuffer and QFile.
[virtual]
Writes the character ch to the I/O device.
Returns ch, or -1 if some error occurred.
This virtual function must be reimplemented by all subclasses.
See also: getch() and ungetch().
Reimplemented in QBuffer and QFile.
[virtual]
Reads at most len bytes from the I/O device into data and returns the number of bytes actually read.
This virtual function must be reimplemented by all subclasses.
See also: writeBlock().
Reimplemented in QBuffer and QFile.
[virtual]
Reads a line of text, up to maxlen bytes including a terminating \0. If there is a newline at the end if the line, it is not stripped.
Returns the number of bytes read, or -1 in case of error.
This virtual function can be reimplemented much more efficiently by the most subclasses.
See also: readBlock() and QTextStream::readLine().
Reimplemented in QBuffer and QFile.
Sets the device index to 0.
See also: at().
Sets the I/O device status to IO_Ok.
See also: status().
[protected]
For internal use only.
[protected]
For internal use only.
[protected]
For internal use only.
[protected]
For internal use only.
[protected]
For internal use only.
[virtual]
Virtual function that returns the size of the I/O device.
See also: at().
Reimplemented in QBuffer and QFile.
Returns bits OR'ed together that specify the current state.
The flags are: IO_Open.
Subclasses may define more flags.
Returns the I/O device status.
The I/O device status returns an error code. If open() returns FALSE or readBlock() or writeBlock() return -1, this function can be called to get the reason why the operation did not succeed.
The status codes are:
IO_Ok
The operation was successful.
IO_ReadError
Could not read from the device.
IO_WriteError
Could not write to the device.
IO_FatalError
A fatal unrecoverable error occurred.
IO_OpenError
Could not open the device.
IO_ConnectError
Could not connect to the device.
IO_AbortError
The operation was unexpectedly aborted.
IO_TimeOutError
The operation timed out.
See also: resetStatus().
[virtual]
Puts the character ch back into the I/O device and decrements the index if it is not zero.
This function is normally called to "undo" a getch() operation.
Returns ch, or -1 if some error occurred.
This virtual function must be reimplemented by all subclasses.
See also: getch() and putch().
Reimplemented in QBuffer and QFile.
[virtual]
Writes len bytes from p to the I/O device and returns the number of bytes actually written.
This virtual function must be reimplemented by all subclasses.
See also: readBlock().
Reimplemented in QBuffer and QFile.
Search the documentation, FAQ, qt-interest archive and more (uses
www.troll.no):
This file is part of the Qt toolkit, copyright © 1995-98 Troll Tech, all rights reserved.
It was generated from the following files:
Copyright © 1998 Troll Tech | Trademarks | Qt version 1.42
|