QIODevice Class ReferenceThe QIODevice class is the base class of I/O devices. More... All the functions in this class are reentrant when Qt is built with thread support. #include <qiodevice.h> Inherited by QBuffer, QFile, QSocket, and QSocketDevice. Public Members
Detailed DescriptionThe 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:
There are also some other, less used, action functions:
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:
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.
See also QDataStream, QTextStream, and Input/Output and Networking. Member Type Documentation
|
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.
See also close().
Example: grapher/grapher.cpp.
Reimplemented in QFile and QSocket.
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.
See also getch() and ungetch().
Example: grapher/grapher.cpp.
Reimplemented in QFile and QSocket.
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.
See also writeBlock(), isOpen(), and isReadable().
Examples: distributor/distributor.ui.h and qwerty/qwerty.cpp.
Reimplemented in QSocket and QSocketDevice.
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.
See also readBlock() and QTextStream::readLine().
Examples: network/clientserver/client/client.cpp, network/httpd/httpd.cpp, network/mail/smtp.cpp, and network/networkprotocol/nntp.cpp.
Reimplemented in QFile.
Sets the device index position to 0.
See also at().
Sets the I/O device status to IO_Ok.
See also status().
Virtual function that returns the size of the I/O device.
See also at().
Reimplemented in QFile and QSocket.
Returns bits OR'ed together that specify the current state.
The flags are: IO_Open.
Subclasses may define additional 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 find out the reason why the operation failed.
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. |
See also resetStatus().
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.
Reimplemented in QFile and QSocket.
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.
See also readBlock().
Example: distributor/distributor.ui.h.
Reimplemented in QBuffer, QSocket, and QSocketDevice.
This convenience function is the same as calling writeBlock( data.data(), data.size() ).
This file is part of the Qt toolkit. Copyright © 1995-2003 Trolltech. All Rights Reserved.
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 3.2 | |
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