Eneboo - Documentación para desarrolladores
|
The QIODevice class is the base class of I/O devices. Más...
#include <qiodevice.h>
Tipos públicos | |
typedef Q_ULONG | Offset |
typedef Q_ULONG | Offset |
Métodos públicos | |
QIODevice () | |
virtual | ~QIODevice () |
int | flags () const |
int | mode () const |
int | state () const |
bool | isDirectAccess () const |
bool | isSequentialAccess () const |
bool | isCombinedAccess () const |
bool | isBuffered () const |
bool | isRaw () const |
bool | isSynchronous () const |
bool | isAsynchronous () const |
bool | isTranslated () const |
bool | isReadable () const |
bool | isWritable () const |
bool | isReadWrite () const |
bool | isInactive () const |
bool | isOpen () const |
int | status () const |
void | resetStatus () |
virtual bool | open (int mode)=0 |
virtual void | close ()=0 |
virtual void | flush ()=0 |
virtual Offset | size () const =0 |
virtual Offset | at () const |
virtual bool | at (Offset) |
virtual bool | atEnd () const |
bool | reset () |
virtual Q_LONG | readBlock (char *data, Q_ULONG maxlen)=0 |
virtual Q_LONG | writeBlock (const char *data, Q_ULONG len)=0 |
virtual Q_LONG | readLine (char *data, Q_ULONG maxlen) |
Q_LONG | writeBlock (const QByteArray &data) |
virtual QByteArray | readAll () |
virtual int | getch ()=0 |
virtual int | putch (int)=0 |
virtual int | ungetch (int)=0 |
QIODevice () | |
virtual | ~QIODevice () |
int | flags () const |
int | mode () const |
int | state () const |
bool | isDirectAccess () const |
bool | isSequentialAccess () const |
bool | isCombinedAccess () const |
bool | isBuffered () const |
bool | isRaw () const |
bool | isSynchronous () const |
bool | isAsynchronous () const |
bool | isTranslated () const |
bool | isReadable () const |
bool | isWritable () const |
bool | isReadWrite () const |
bool | isInactive () const |
bool | isOpen () const |
int | status () const |
void | resetStatus () |
virtual bool | open (int mode)=0 |
virtual void | close ()=0 |
virtual void | flush ()=0 |
virtual Offset | size () const =0 |
virtual Offset | at () const |
virtual bool | at (Offset) |
virtual bool | atEnd () const |
bool | reset () |
virtual Q_LONG | readBlock (char *data, Q_ULONG maxlen)=0 |
virtual Q_LONG | writeBlock (const char *data, Q_ULONG len)=0 |
virtual Q_LONG | readLine (char *data, Q_ULONG maxlen) |
Q_LONG | writeBlock (const QByteArray &data) |
virtual QByteArray | readAll () |
virtual int | getch ()=0 |
virtual int | putch (int)=0 |
virtual int | ungetch (int)=0 |
Métodos protegidos | |
void | setFlags (int f) |
void | setType (int) |
void | setMode (int) |
void | setState (int) |
void | setStatus (int) |
void | setFlags (int f) |
void | setType (int) |
void | setMode (int) |
void | setState (int) |
void | setStatus (int) |
Atributos protegidos | |
Offset | ioIndex |
The QIODevice class is the base class of I/O devices.
An I/O device represents a medium that one can read bytes from and/or write bytes to. The QIODevice class is the abstract superclass of all such devices; classes such as QFile, QBuffer and QSocket inherit QIODevice and implement virtual functions such as write() appropriately.
Although applications sometimes use QIODevice directly, it is usually better to use QTextStream and QDataStream, which provide stream operations on any QIODevice subclass. QTextStream provides text-oriented stream functionality (for human-readable ASCII files, for example), whereas QDataStream deals with binary data in a totally platform-independent manner.
The public member functions in QIODevice roughly fall into two groups: the action functions and the state access functions. The most important action functions are:
open() opens a device for reading and/or writing, depending on the mode argument.
close() closes the device and tidies up (e.g. flushes buffered data)
readBlock() reads a block of data from the device.
writeBlock() writes a block of data to the device.
readLine() reads a line (of text, usually) from the device.
flush() ensures that all buffered data are written to the real device.
There are also some other, less used, action functions:
getch() reads a single character.
ungetch() forgets the last call to getch(), if possible.
putch() writes a single character.
size() returns the size of the device, if there is one.
at() returns the current read/write pointer's position, if there is one for this device, or it moves the pointer if given an offset.
atEnd() indicates whether there is more to read, if this is meaningful for this device.
reset() moves the read/write pointer to the start of the device, if that is possible for this device.
The state access are all "get" functions. The QIODevice subclass calls setState() to update the state, and simple access functions tell the user of the device what the device's state is. Here are the settings, and their associated access functions:
Access type. Some devices are direct access (it is possible to read/write anywhere), whereas others are sequential. QIODevice provides the access functions (isDirectAccess(), isSequentialAccess(), and isCombinedAccess()) to tell users what a given I/O device supports.
Buffering. Some devices are accessed in raw mode, whereas others are buffered. Buffering usually provides greater efficiency, particularly for small read/write operations. isBuffered() tells the user whether a given device is buffered. (This can often be set by the application in the call to open().)
Synchronicity. Synchronous devices work immediately (for example, files). When you read from a file, the file delivers its data straight away. Other kinds of device, such as a socket connected to a HTTP server, may not deliver the data until seconds after you ask to read it. isSynchronous() and isAsynchronous() tell the user how this device operates.
CR/LF translation. For simplicity, applications often like to see just a single CR/LF style, and QIODevice subclasses can provide this. isTranslated() returns TRUE if this object translates CR/LF to just LF. (This can often be set by the application in the call to open().)
Permissions. Some files cannot be written. For example, isReadable(), isWritable() and isReadWrite() tell the application whether it can read from and write to a given device. (This can often be set by the application in the call to open().)
Finally, isOpen() returns TRUE if the device is open, i.e. after an open() call.
QIODevice provides numerous pure virtual functions that you need to implement when subclassing it. Here is a skeleton subclass with all the members you are sure to need and some that you will probably need:
class MyDevice : public QIODevice { public: MyDevice(); ~MyDevice(); bool open( int mode ); void close(); void flush(); uint size() const; int at() const; // non-pure virtual bool at( int ); // non-pure virtual bool atEnd() const; // non-pure virtual int readBlock( char *data, uint maxlen ); 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 need not be reimplemented for sequential devices.
typedef Q_ULONG QIODevice::Offset |
typedef Q_ULONG QIODevice::Offset |
QIODevice::QIODevice | ( | ) |
Constructs an I/O device.
QIODevice::~QIODevice | ( | ) | [virtual] |
Destroys the I/O device.
QIODevice::QIODevice | ( | ) |
virtual QIODevice::~QIODevice | ( | ) | [virtual] |
QIODevice::Offset QIODevice::at | ( | ) | const [virtual] |
Virtual function that returns the current I/O device position.
This is the position of the data read/write head of the I/O device.
Reimplementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile y QStringBuffer.
Virtual function that sets the I/O device position to pos. Returns TRUE if the position was successfully set, i.e. pos is within range and the seek was successful; otherwise returns FALSE.
Reimplementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual Offset QIODevice::at | ( | ) | const [virtual] |
Reimplementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile y QStringBuffer.
Reimplementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual bool QIODevice::atEnd | ( | ) | const [virtual] |
Reimplementado en QFile, QSocket, QSocketDevice, QSocket, QSocketDevice y QFile.
bool QIODevice::atEnd | ( | ) | const [virtual] |
Virtual function that returns TRUE if the I/O device position is at the end of the input; otherwise returns FALSE.
Reimplementado en QFile, QSocket, QSocketDevice, QSocket, QSocketDevice y QFile.
void QIODevice::close | ( | void | ) | [pure virtual] |
Closes the I/O device.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual void QIODevice::close | ( | ) | [pure virtual] |
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
int QIODevice::flags | ( | ) | const [inline] |
int QIODevice::flags | ( | ) | const [inline] |
void QIODevice::flush | ( | ) | [pure virtual] |
Flushes an open I/O device.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual void QIODevice::flush | ( | ) | [pure virtual] |
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
int QIODevice::getch | ( | ) | [pure 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.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual int QIODevice::getch | ( | ) | [pure virtual] |
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
bool QIODevice::isAsynchronous | ( | ) | const [inline] |
Returns TRUE if the device is an asynchronous device; otherwise returns FALSE, i.e. if the device is a synchronous device.
This mode is currently not in use.
bool QIODevice::isAsynchronous | ( | ) | const [inline] |
bool QIODevice::isBuffered | ( | ) | const [inline] |
bool QIODevice::isBuffered | ( | ) | const [inline] |
Returns TRUE if the I/O device is a buffered device; otherwise returns FALSE, i.e. the device is a raw device.
bool QIODevice::isCombinedAccess | ( | ) | const [inline] |
bool QIODevice::isCombinedAccess | ( | ) | const [inline] |
Returns TRUE if the I/O device is a combined access (both direct and sequential) device; otherwise returns FALSE.
This access method is currently not in use.
bool QIODevice::isDirectAccess | ( | ) | const [inline] |
Returns TRUE if the I/O device is a direct access device; otherwise returns FALSE, i.e. if the device is a sequential access device.
bool QIODevice::isDirectAccess | ( | ) | const [inline] |
bool QIODevice::isInactive | ( | ) | const [inline] |
bool QIODevice::isInactive | ( | ) | const [inline] |
Returns TRUE if the I/O device state is 0, i.e. the device is not open; otherwise returns FALSE.
bool QIODevice::isOpen | ( | ) | const [inline] |
Returns TRUE if the I/O device has been opened; otherwise returns FALSE.
bool QIODevice::isOpen | ( | ) | const [inline] |
bool QIODevice::isRaw | ( | ) | const [inline] |
Returns TRUE if the device is a raw device; otherwise returns FALSE, i.e. if the device is a buffered device.
bool QIODevice::isRaw | ( | ) | const [inline] |
bool QIODevice::isReadable | ( | ) | const [inline] |
Returns TRUE if the I/O device was opened using IO_ReadOnly
or IO_ReadWrite
mode; otherwise returns FALSE.
bool QIODevice::isReadable | ( | ) | const [inline] |
bool QIODevice::isReadWrite | ( | ) | const [inline] |
bool QIODevice::isReadWrite | ( | ) | const [inline] |
Returns TRUE if the I/O device was opened using IO_ReadWrite
mode; otherwise returns FALSE.
bool QIODevice::isSequentialAccess | ( | ) | const [inline] |
Returns TRUE if the device is a sequential access device; otherwise returns FALSE, i.e. if the device is a direct access device.
Operations involving size() and at(int) are not valid on sequential devices.
bool QIODevice::isSequentialAccess | ( | ) | const [inline] |
bool QIODevice::isSynchronous | ( | ) | const [inline] |
Returns TRUE if the I/O device is a synchronous device; otherwise returns FALSE, i.e. the device is an asynchronous device.
bool QIODevice::isSynchronous | ( | ) | const [inline] |
bool QIODevice::isTranslated | ( | ) | const [inline] |
Returns TRUE if the I/O device translates carriage-return and linefeed characters; otherwise returns FALSE.
A QFile is translated if it is opened with the IO_Translate
mode flag.
bool QIODevice::isTranslated | ( | ) | const [inline] |
bool QIODevice::isWritable | ( | ) | const [inline] |
bool QIODevice::isWritable | ( | ) | const [inline] |
Returns TRUE if the I/O device was opened using IO_WriteOnly
or IO_ReadWrite
mode; otherwise returns FALSE.
int QIODevice::mode | ( | ) | const [inline] |
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
.
int QIODevice::mode | ( | ) | const [inline] |
Opens the I/O device using the specified mode. Returns TRUE if the device was successfully opened; otherwise returns FALSE.
The mode parameter mode must be an OR'ed combination of the following flags. Mode flags Meaning IO_Raw
specifies 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, Windows and Macintosh. On Unix systems this flag has no effect. Use with caution as it will also transform every linefeed written to the file into a CRLF pair. This is likely to corrupt your file if you write write binary data. Cannot be combined with IO_Raw
.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
Writes the character ch to the I/O device.
Returns ch, or -1 if an error occurred.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual QByteArray QIODevice::readAll | ( | ) | [virtual] |
QByteArray QIODevice::readAll | ( | ) | [virtual] |
This convenience function returns all of the remaining data in the device.
virtual Q_LONG QIODevice::readBlock | ( | char * | data, |
Q_ULONG | maxlen | ||
) | [pure virtual] |
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
int QIODevice::readBlock | ( | char * | data, |
Q_ULONG | maxlen | ||
) | [pure virtual] |
Reads at most maxlen bytes from the I/O device into data and returns the number of bytes actually read.
This function should return -1 if a fatal error occurs and should return 0 if there are no bytes to read.
The device must be opened for reading, and data must not be 0.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
Q_LONG QIODevice::readLine | ( | char * | data, |
Q_ULONG | maxlen | ||
) | [virtual] |
Reads a line of text, (or up to maxlen bytes if a newline isn't encountered) plus a terminating '\0' into data. If there is a newline at the end if the line, it is not stripped.
Returns the number of bytes read including the terminating '\0', or -1 if an error occurred.
This virtual function can be reimplemented much more efficiently by the most subclasses.
Reimplementado en QBuffer, QFile, QSocket, QSocket, QBuffer y QFile.
virtual Q_LONG QIODevice::readLine | ( | char * | data, |
Q_ULONG | maxlen | ||
) | [virtual] |
bool QIODevice::reset | ( | void | ) | [inline] |
void QIODevice::resetStatus | ( | ) | [inline] |
Sets the I/O device status to IO_Ok
.
void QIODevice::resetStatus | ( | ) | [inline] |
void QIODevice::setFlags | ( | int | flags | ) | [inline, protected] |
Used by subclasses to set the device flags to the flags specified.
void QIODevice::setFlags | ( | int | f | ) | [inline, protected] |
void QIODevice::setMode | ( | int | ) | [protected] |
void QIODevice::setMode | ( | int | mode | ) | [protected] |
Used by subclasses to set the device mode to the mode specified.
void QIODevice::setState | ( | int | ) | [protected] |
void QIODevice::setState | ( | int | state | ) | [protected] |
Used by subclasses to set the device state to the state specified.
void QIODevice::setStatus | ( | int | ) | [protected] |
void QIODevice::setStatus | ( | int | s | ) | [protected] |
Used by subclasses to set the device status (not state) to s.
void QIODevice::setType | ( | int | ) | [protected] |
void QIODevice::setType | ( | int | type | ) | [protected] |
Used by subclasses to set the device type to the type specified.
QIODevice::Offset QIODevice::size | ( | ) | const [pure virtual] |
Virtual function that returns the size of the I/O device.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual Offset QIODevice::size | ( | ) | const [pure virtual] |
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
int QIODevice::state | ( | ) | const [inline] |
int QIODevice::status | ( | ) | const [inline] |
int QIODevice::status | ( | ) | const [inline] |
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 find out the reason why the operation failed.
IO_Ok IO_ReadError IO_WriteError IO_FatalError IO_OpenError IO_ConnectError IO_AbortError IO_TimeOutError IO_UnspecifiedError
The status codes are: Status code Meaning 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. IO_UnspecifiedError
An unspecified error happened on close.
Puts the character ch back into the I/O device and decrements the index position if it is not zero.
This function is normally called to "undo" a getch() operation.
Returns ch, or -1 if an error occurred.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
int QIODevice::writeBlock | ( | const char * | data, |
Q_ULONG | len | ||
) | [pure virtual] |
Writes len bytes from data to the I/O device and returns the number of bytes actually written.
This function should return -1 if a fatal error occurs.
This virtual function must be reimplemented by all subclasses.
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
virtual Q_LONG QIODevice::writeBlock | ( | const char * | data, |
Q_ULONG | len | ||
) | [pure virtual] |
Implementado en QBuffer, QFile, QSocket, QSocketDevice, QSocket, QSocketDevice, QBuffer, QFile, QStringBuffer y QextSerialPort.
Q_LONG QIODevice::writeBlock | ( | const QByteArray & | data | ) |
Q_LONG QIODevice::writeBlock | ( | const QByteArray & | data | ) |
Offset QIODevice::ioIndex [protected] |