source: trunk/doc/html/qiodevice.html@ 203

Last change on this file since 203 was 190, checked in by rudi, 14 years ago

reference documentation added

File size: 28.9 KB
Line 
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qiodevice.cpp:40 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QIODevice Class</title>
7<style type="text/css"><!--
8fn { margin-left: 1cm; text-indent: -1cm; }
9a:link { color: #004faf; text-decoration: none }
10a:visited { color: #672967; text-decoration: none }
11body { background: #ffffff; color: black; }
12--></style>
13</head>
14<body>
15
16<table border="0" cellpadding="0" cellspacing="0" width="100%">
17<tr bgcolor="#E5E5E5">
18<td valign=center>
19 <a href="index.html">
20<font color="#004faf">Home</font></a>
21 | <a href="classes.html">
22<font color="#004faf">All&nbsp;Classes</font></a>
23 | <a href="mainclasses.html">
24<font color="#004faf">Main&nbsp;Classes</font></a>
25 | <a href="annotated.html">
26<font color="#004faf">Annotated</font></a>
27 | <a href="groups.html">
28<font color="#004faf">Grouped&nbsp;Classes</font></a>
29 | <a href="functions.html">
30<font color="#004faf">Functions</font></a>
31</td>
32<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QIODevice Class Reference</h1>
33
34<p>The QIODevice class is the base class of I/O devices.
35<a href="#details">More...</a>
36<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
37<p><tt>#include &lt;<a href="qiodevice-h.html">qiodevice.h</a>&gt;</tt>
38<p>Inherited by <a href="qbuffer.html">QBuffer</a>, <a href="qfile.html">QFile</a>, <a href="qsocket.html">QSocket</a>, and <a href="qsocketdevice.html">QSocketDevice</a>.
39<p><a href="qiodevice-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn>typedef Q_ULONG&nbsp;<a href="#Offset"><b>Offset</b></a></li>
43<li class=fn><a href="#QIODevice"><b>QIODevice</b></a> ()</li>
44<li class=fn>virtual <a href="#~QIODevice"><b>~QIODevice</b></a> ()</li>
45<li class=fn>int <a href="#flags"><b>flags</b></a> () const</li>
46<li class=fn>int <a href="#mode"><b>mode</b></a> () const</li>
47<li class=fn>int <a href="#state"><b>state</b></a> () const</li>
48<li class=fn>bool <a href="#isDirectAccess"><b>isDirectAccess</b></a> () const</li>
49<li class=fn>bool <a href="#isSequentialAccess"><b>isSequentialAccess</b></a> () const</li>
50<li class=fn>bool <a href="#isCombinedAccess"><b>isCombinedAccess</b></a> () const</li>
51<li class=fn>bool <a href="#isBuffered"><b>isBuffered</b></a> () const</li>
52<li class=fn>bool <a href="#isRaw"><b>isRaw</b></a> () const</li>
53<li class=fn>bool <a href="#isSynchronous"><b>isSynchronous</b></a> () const</li>
54<li class=fn>bool <a href="#isAsynchronous"><b>isAsynchronous</b></a> () const</li>
55<li class=fn>bool <a href="#isTranslated"><b>isTranslated</b></a> () const</li>
56<li class=fn>bool <a href="#isReadable"><b>isReadable</b></a> () const</li>
57<li class=fn>bool <a href="#isWritable"><b>isWritable</b></a> () const</li>
58<li class=fn>bool <a href="#isReadWrite"><b>isReadWrite</b></a> () const</li>
59<li class=fn>bool <a href="#isInactive"><b>isInactive</b></a> () const</li>
60<li class=fn>bool <a href="#isOpen"><b>isOpen</b></a> () const</li>
61<li class=fn>int <a href="#status"><b>status</b></a> () const</li>
62<li class=fn>void <a href="#resetStatus"><b>resetStatus</b></a> ()</li>
63<li class=fn>virtual bool <a href="#open"><b>open</b></a> ( int&nbsp;mode ) = 0</li>
64<li class=fn>virtual void <a href="#close"><b>close</b></a> () = 0</li>
65<li class=fn>virtual void <a href="#flush"><b>flush</b></a> () = 0</li>
66<li class=fn>virtual Offset <a href="#size"><b>size</b></a> () const = 0</li>
67<li class=fn>virtual Offset <a href="#at"><b>at</b></a> () const</li>
68<li class=fn>virtual bool <a href="#at-2"><b>at</b></a> ( Offset&nbsp;pos )</li>
69<li class=fn>virtual bool <a href="#atEnd"><b>atEnd</b></a> () const</li>
70<li class=fn>bool <a href="#reset"><b>reset</b></a> ()</li>
71<li class=fn>virtual Q_LONG <a href="#readBlock"><b>readBlock</b></a> ( char&nbsp;*&nbsp;data, Q_ULONG&nbsp;maxlen ) = 0</li>
72<li class=fn>virtual Q_LONG <a href="#writeBlock"><b>writeBlock</b></a> ( const&nbsp;char&nbsp;*&nbsp;data, Q_ULONG&nbsp;len ) = 0</li>
73<li class=fn>virtual Q_LONG <a href="#readLine"><b>readLine</b></a> ( char&nbsp;*&nbsp;data, Q_ULONG&nbsp;maxlen )</li>
74<li class=fn>Q_LONG <a href="#writeBlock-2"><b>writeBlock</b></a> ( const&nbsp;QByteArray&nbsp;&amp;&nbsp;data )</li>
75<li class=fn>virtual QByteArray <a href="#readAll"><b>readAll</b></a> ()</li>
76<li class=fn>virtual int <a href="#getch"><b>getch</b></a> () = 0</li>
77<li class=fn>virtual int <a href="#putch"><b>putch</b></a> ( int&nbsp;ch ) = 0</li>
78<li class=fn>virtual int <a href="#ungetch"><b>ungetch</b></a> ( int&nbsp;ch ) = 0</li>
79</ul>
80<h2>Protected Members</h2>
81<ul>
82<li class=fn>void <a href="#setFlags"><b>setFlags</b></a> ( int&nbsp;flags )</li>
83<li class=fn>void <a href="#setType"><b>setType</b></a> ( int&nbsp;type )</li>
84<li class=fn>void <a href="#setMode"><b>setMode</b></a> ( int&nbsp;mode )</li>
85<li class=fn>void <a href="#setState"><b>setState</b></a> ( int&nbsp;state )</li>
86<li class=fn>void <a href="#setStatus"><b>setStatus</b></a> ( int&nbsp;s )</li>
87</ul>
88<hr><a name="details"></a><h2>Detailed Description</h2>
89
90
91
92<p> The QIODevice class is the base class of I/O devices.
93<p>
94<p> An I/O device represents a medium that one can read bytes from
95and/or write bytes to. The QIODevice class is the abstract
96superclass of all such devices; classes such as <a href="qfile.html">QFile</a>, <a href="qbuffer.html">QBuffer</a> and
97<a href="qsocket.html">QSocket</a> inherit QIODevice and implement virtual functions such as
98write() appropriately.
99<p> Although applications sometimes use QIODevice directly, it is
100usually better to use <a href="qtextstream.html">QTextStream</a> and <a href="qdatastream.html">QDataStream</a>, which provide
101stream operations on any QIODevice subclass. QTextStream provides
102text-oriented stream functionality (for human-readable ASCII
103files, for example), whereas QDataStream deals with binary data in
104a totally platform-independent manner.
105<p> The public member functions in QIODevice roughly fall into two
106groups: the action functions and the state access functions. The
107most important action functions are:
108<p> <ul>
109<p> <li> <a href="#open">open</a>() opens a device for reading and/or writing, depending on
110the mode argument.
111<p> <li> <a href="#close">close</a>() closes the device and tidies up (e.g. flushes buffered
112data)
113<p> <li> <a href="#readBlock">readBlock</a>() reads a block of data from the device.
114<p> <li> <a href="#writeBlock">writeBlock</a>() writes a block of data to the device.
115<p> <li> <a href="#readLine">readLine</a>() reads a line (of text, usually) from the device.
116<p> <li> <a href="#flush">flush</a>() ensures that all buffered data are written to the real device.
117<p> </ul>
118<p> There are also some other, less used, action functions:
119<p> <ul>
120<p> <li> <a href="#getch">getch</a>() reads a single character.
121<p> <li> <a href="#ungetch">ungetch</a>() forgets the last call to getch(), if possible.
122<p> <li> <a href="#putch">putch</a>() writes a single character.
123<p> <li> <a href="#size">size</a>() returns the size of the device, if there is one.
124<p> <li> <a href="#at">at</a>() returns the current read/write pointer's position, if there
125is one for this device, or it moves the pointer if given an offset.
126<p> <li> <a href="#atEnd">atEnd</a>() indicates whether there is more to read, if this is
127meaningful for this device.
128<p> <li> <a href="#reset">reset</a>() moves the read/write pointer to the start of the
129device, if that is possible for this device.
130<p> </ul>
131<p> The state access are all "get" functions. The QIODevice subclass
132calls <a href="#setState">setState</a>() to update the state, and simple access functions
133tell the user of the device what the device's state is. Here are
134the settings, and their associated access functions:
135<p> <ul>
136<p> <li> Access type. Some devices are direct access (it is possible
137to read/write anywhere), whereas others are sequential. QIODevice
138provides the access functions (<a href="#isDirectAccess">isDirectAccess</a>(),
139<a href="#isSequentialAccess">isSequentialAccess</a>(), and <a href="#isCombinedAccess">isCombinedAccess</a>()) to tell users what a
140given I/O device supports.
141<p> <li> Buffering. Some devices are accessed in raw mode, whereas
142others are buffered. Buffering usually provides greater
143efficiency, particularly for small read/write operations.
144<a href="#isBuffered">isBuffered</a>() tells the user whether a given device is buffered.
145(This can often be set by the application in the call to <a href="#open">open</a>().)
146<p> <li> Synchronicity. Synchronous devices work immediately (for
147example, files). When you read from a file, the file delivers its
148data straight away. Other kinds of device, such as a socket
149connected to a HTTP server, may not deliver the data until seconds
150after you ask to read it. <a href="#isSynchronous">isSynchronous</a>() and <a href="#isAsynchronous">isAsynchronous</a>()
151tell the user how this device operates.
152<p> <li> CR/LF translation. For simplicity, applications often like to
153see just a single CR/LF style, and QIODevice subclasses can
154provide this. <a href="#isTranslated">isTranslated</a>() returns TRUE if this object
155translates CR/LF to just LF. (This can often be set by the
156application in the call to open().)
157<p> <li> Permissions. Some files cannot be written. For example,
158<a href="#isReadable">isReadable</a>(), <a href="#isWritable">isWritable</a>() and <a href="#isReadWrite">isReadWrite</a>() tell the application
159whether it can read from and write to a given device. (This can
160often be set by the application in the call to <a href="#open">open</a>().)
161<p> <li> Finally, <a href="#isOpen">isOpen</a>() returns TRUE if the device is open, i.e.
162after an open() call.
163<p> </ul>
164<p> QIODevice provides numerous pure virtual functions that you need
165to implement when subclassing it. Here is a skeleton subclass with
166all the members you are sure to need and some that you will
167probably need:
168<p> <pre>
169 class MyDevice : public QIODevice
170 {
171 public:
172 MyDevice();
173 ~MyDevice();
174
175 bool open( int mode );
176 void close();
177 void flush();
178
179 uint size() const;
180 int at() const; // non-pure virtual
181 bool at( int ); // non-pure virtual
182 bool atEnd() const; // non-pure virtual
183
184 int readBlock( char *data, uint maxlen );
185 int writeBlock( const char *data, uint len );
186 int readLine( char *data, uint maxlen );
187
188 int getch();
189 int putch( int );
190 int ungetch( int );
191 };
192 </pre>
193
194<p> The three non-pure virtual functions need not be reimplemented for
195sequential devices.
196<p> <p>See also <a href="qdatastream.html">QDataStream</a>, <a href="qtextstream.html">QTextStream</a>, and <a href="io.html">Input/Output and Networking</a>.
197
198<hr><h2>Member Type Documentation</h2>
199<h3 class=fn><a name="Offset"></a>QIODevice::Offset</h3>
200
201<p> The offset within the device.
202
203<hr><h2>Member Function Documentation</h2>
204<h3 class=fn><a name="QIODevice"></a>QIODevice::QIODevice ()
205</h3>
206Constructs an I/O device.
207
208<h3 class=fn><a name="~QIODevice"></a>QIODevice::~QIODevice ()<tt> [virtual]</tt>
209</h3>
210Destroys the I/O device.
211
212<h3 class=fn><a href="qiodevice.html#Offset">Offset</a> <a name="at"></a>QIODevice::at () const<tt> [virtual]</tt>
213</h3>
214Virtual function that returns the current I/O device position.
215<p> This is the position of the data read/write head of the I/O
216device.
217<p> <p>See also <a href="#size">size</a>().
218
219<p>Example: <a href="distributor-example.html#x2666">distributor/distributor.ui.h</a>.
220<p>Reimplemented in <a href="qsocket.html#at">QSocket</a>.
221<h3 class=fn>bool <a name="at-2"></a>QIODevice::at ( <a href="qiodevice.html#Offset">Offset</a>&nbsp;pos )<tt> [virtual]</tt>
222</h3>
223Virtual function that sets the I/O device position to <em>pos</em>.
224Returns TRUE if the position was successfully set, i.e. <em>pos</em> is
225within range and the seek was successful; otherwise returns FALSE.
226<p> <p>See also <a href="#size">size</a>().
227
228<p>Reimplemented in <a href="qsocket.html#at-2">QSocket</a>.
229<h3 class=fn>bool <a name="atEnd"></a>QIODevice::atEnd () const<tt> [virtual]</tt>
230</h3>
231Virtual function that returns TRUE if the I/O device position is
232at the end of the input; otherwise returns FALSE.
233
234<p>Reimplemented in <a href="qfile.html#atEnd">QFile</a> and <a href="qsocket.html#atEnd">QSocket</a>.
235<h3 class=fn>void <a name="close"></a>QIODevice::close ()<tt> [pure virtual]</tt>
236</h3>
237
238<p> Closes the I/O device.
239<p> This virtual function must be reimplemented by all subclasses.
240<p> <p>See also <a href="#open">open</a>().
241
242<p>Example: <a href="grapher-nsplugin-example.html#x2742">grapher/grapher.cpp</a>.
243<p>Reimplemented in <a href="qfile.html#close">QFile</a> and <a href="qsocket.html#close">QSocket</a>.
244<h3 class=fn>int <a name="flags"></a>QIODevice::flags () const
245</h3>
246
247<p> Returns the current I/O device flags setting.
248<p> Flags consists of mode flags and state flags.
249<p> <p>See also <a href="#mode">mode</a>() and <a href="#state">state</a>().
250
251<h3 class=fn>void <a name="flush"></a>QIODevice::flush ()<tt> [pure virtual]</tt>
252</h3>
253
254<p> Flushes an open I/O device.
255<p> This virtual function must be reimplemented by all subclasses.
256
257<p>Reimplemented in <a href="qfile.html#flush">QFile</a> and <a href="qsocket.html#flush">QSocket</a>.
258<h3 class=fn>int <a name="getch"></a>QIODevice::getch ()<tt> [pure virtual]</tt>
259</h3>
260
261<p> Reads a single byte/character from the I/O device.
262<p> Returns the byte/character read, or -1 if the end of the I/O
263device has been reached.
264<p> This virtual function must be reimplemented by all subclasses.
265<p> <p>See also <a href="#putch">putch</a>() and <a href="#ungetch">ungetch</a>().
266
267<p>Reimplemented in <a href="qfile.html#getch">QFile</a> and <a href="qsocket.html#getch">QSocket</a>.
268<h3 class=fn>bool <a name="isAsynchronous"></a>QIODevice::isAsynchronous () const
269</h3>
270
271<p> Returns TRUE if the device is an asynchronous device; otherwise
272returns FALSE, i.e. if the device is a synchronous device.
273<p> This mode is currently not in use.
274<p> <p>See also <a href="#isSynchronous">isSynchronous</a>().
275
276<h3 class=fn>bool <a name="isBuffered"></a>QIODevice::isBuffered () const
277</h3>
278
279<p> Returns TRUE if the I/O device is a buffered device; otherwise
280returns FALSE, i.e. the device is a raw device.
281<p> <p>See also <a href="#isRaw">isRaw</a>().
282
283<h3 class=fn>bool <a name="isCombinedAccess"></a>QIODevice::isCombinedAccess () const
284</h3>
285
286<p> Returns TRUE if the I/O device is a combined access (both direct
287and sequential) device; otherwise returns FALSE.
288<p> This access method is currently not in use.
289
290<h3 class=fn>bool <a name="isDirectAccess"></a>QIODevice::isDirectAccess () const
291</h3>
292
293<p> Returns TRUE if the I/O device is a direct access device;
294otherwise returns FALSE, i.e. if the device is a sequential access
295device.
296<p> <p>See also <a href="#isSequentialAccess">isSequentialAccess</a>().
297
298<h3 class=fn>bool <a name="isInactive"></a>QIODevice::isInactive () const
299</h3>
300
301<p> Returns TRUE if the I/O device state is 0, i.e. the device is not
302open; otherwise returns FALSE.
303<p> <p>See also <a href="#isOpen">isOpen</a>().
304
305<h3 class=fn>bool <a name="isOpen"></a>QIODevice::isOpen () const
306</h3>
307
308<p> Returns TRUE if the I/O device has been opened; otherwise returns
309FALSE.
310<p> <p>See also <a href="#isInactive">isInactive</a>().
311
312<p>Example: <a href="networkprotocol-example.html#x670">network/networkprotocol/nntp.cpp</a>.
313<h3 class=fn>bool <a name="isRaw"></a>QIODevice::isRaw () const
314</h3>
315
316<p> Returns TRUE if the device is a raw device; otherwise returns
317FALSE, i.e. if the device is a buffered device.
318<p> <p>See also <a href="#isBuffered">isBuffered</a>().
319
320<h3 class=fn>bool <a name="isReadWrite"></a>QIODevice::isReadWrite () const
321</h3>
322
323<p> Returns TRUE if the I/O device was opened using <a href="qfile.html#open">IO_ReadWrite</a>
324mode; otherwise returns FALSE.
325<p> <p>See also <a href="#isReadable">isReadable</a>() and <a href="#isWritable">isWritable</a>().
326
327<h3 class=fn>bool <a name="isReadable"></a>QIODevice::isReadable () const
328</h3>
329
330<p> Returns TRUE if the I/O device was opened using <a href="qfile.html#open">IO_ReadOnly</a> or
331<a href="qfile.html#open">IO_ReadWrite</a> mode; otherwise returns FALSE.
332<p> <p>See also <a href="#isWritable">isWritable</a>() and <a href="#isReadWrite">isReadWrite</a>().
333
334<h3 class=fn>bool <a name="isSequentialAccess"></a>QIODevice::isSequentialAccess () const
335</h3>
336
337<p> Returns TRUE if the device is a sequential access device;
338otherwise returns FALSE, i.e. if the device is a direct access
339device.
340<p> Operations involving <a href="#size">size</a>() and <a href="#at">at</a>(int) are not valid on
341sequential devices.
342<p> <p>See also <a href="#isDirectAccess">isDirectAccess</a>().
343
344<h3 class=fn>bool <a name="isSynchronous"></a>QIODevice::isSynchronous () const
345</h3>
346
347<p> Returns TRUE if the I/O device is a synchronous device; otherwise
348returns FALSE, i.e. the device is an asynchronous device.
349<p> <p>See also <a href="#isAsynchronous">isAsynchronous</a>().
350
351<h3 class=fn>bool <a name="isTranslated"></a>QIODevice::isTranslated () const
352</h3>
353
354<p> Returns TRUE if the I/O device translates carriage-return and
355linefeed characters; otherwise returns FALSE.
356<p> A <a href="qfile.html">QFile</a> is translated if it is opened with the <a href="qfile.html#open">IO_Translate</a>
357mode flag.
358
359<h3 class=fn>bool <a name="isWritable"></a>QIODevice::isWritable () const
360</h3>
361
362<p> Returns TRUE if the I/O device was opened using <a href="qfile.html#open">IO_WriteOnly</a> or
363<a href="qfile.html#open">IO_ReadWrite</a> mode; otherwise returns FALSE.
364<p> <p>See also <a href="#isReadable">isReadable</a>() and <a href="#isReadWrite">isReadWrite</a>().
365
366<h3 class=fn>int <a name="mode"></a>QIODevice::mode () const
367</h3>
368
369<p> Returns bits OR'ed together that specify the current operation
370mode.
371<p> These are the flags that were given to the <a href="#open">open</a>() function.
372<p> The flags are <a href="qfile.html#open">IO_ReadOnly</a>, <a href="qfile.html#open">IO_WriteOnly</a>, <a href="qfile.html#open">IO_ReadWrite</a>,
373<a href="qfile.html#open">IO_Append</a>, <a href="qfile.html#open">IO_Truncate</a> and <a href="qfile.html#open">IO_Translate</a>.
374
375<h3 class=fn>bool <a name="open"></a>QIODevice::open ( int&nbsp;mode )<tt> [pure virtual]</tt>
376</h3>
377
378<p> Opens the I/O device using the specified <em>mode</em>. Returns TRUE if
379the device was successfully opened; otherwise returns FALSE.
380<p> The mode parameter <em>mode</em> must be an OR'ed combination of the
381following flags.
382<center><table cellpadding="4" cellspacing="2" border="0">
383<tr bgcolor="#a2c511"> <th valign="top">Mode flags <th valign="top">Meaning
384<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qfile.html#open">IO_Raw</a> <td valign="top">specifies raw (unbuffered) file access.
385<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qfile.html#open">IO_ReadOnly</a> <td valign="top">opens a file in read-only mode.
386<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qfile.html#open">IO_WriteOnly</a> <td valign="top">opens a file in write-only mode.
387<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qfile.html#open">IO_ReadWrite</a> <td valign="top">opens a file in read/write mode.
388<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qfile.html#open">IO_Append</a> <td valign="top">sets the file index to the end of the file.
389<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qfile.html#open">IO_Truncate</a> <td valign="top">truncates the file.
390<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qfile.html#open">IO_Translate</a> <td valign="top">enables carriage returns and linefeed
391translation for text files under MS-DOS, Windows and Macintosh. On
392Unix systems this flag has no effect. Use with caution as it will
393also transform every linefeed written to the file into a CRLF
394pair. This is likely to corrupt your file if you write write
395binary data. Cannot be combined with <a href="qfile.html#open">IO_Raw</a>.
396</table></center>
397<p> This virtual function must be reimplemented by all subclasses.
398<p> <p>See also <a href="#close">close</a>().
399
400<p>Example: <a href="grapher-nsplugin-example.html#x2743">grapher/grapher.cpp</a>.
401<p>Reimplemented in <a href="qfile.html#open">QFile</a> and <a href="qsocket.html#open">QSocket</a>.
402<h3 class=fn>int <a name="putch"></a>QIODevice::putch ( int&nbsp;ch )<tt> [pure virtual]</tt>
403</h3>
404
405<p> Writes the character <em>ch</em> to the I/O device.
406<p> Returns <em>ch</em>, or -1 if an error occurred.
407<p> This virtual function must be reimplemented by all subclasses.
408<p> <p>See also <a href="#getch">getch</a>() and <a href="#ungetch">ungetch</a>().
409
410<p>Example: <a href="grapher-nsplugin-example.html#x2744">grapher/grapher.cpp</a>.
411<p>Reimplemented in <a href="qfile.html#putch">QFile</a> and <a href="qsocket.html#putch">QSocket</a>.
412<h3 class=fn><a href="qbytearray.html">QByteArray</a> <a name="readAll"></a>QIODevice::readAll ()<tt> [virtual]</tt>
413</h3>
414This convenience function returns all of the remaining data in the
415device.
416
417<h3 class=fn>Q_LONG <a name="readBlock"></a>QIODevice::readBlock ( char&nbsp;*&nbsp;data, Q_ULONG&nbsp;maxlen )<tt> [pure virtual]</tt>
418</h3>
419
420<p> Reads at most <em>maxlen</em> bytes from the I/O device into <em>data</em> and
421returns the number of bytes actually read.
422<p> This function should return -1 if a fatal error occurs and should
423return 0 if there are no bytes to read.
424<p> The device must be opened for reading, and <em>data</em> must not be 0.
425<p> This virtual function must be reimplemented by all subclasses.
426<p> <p>See also <a href="#writeBlock">writeBlock</a>(), <a href="#isOpen">isOpen</a>(), and <a href="#isReadable">isReadable</a>().
427
428<p>Example: <a href="distributor-example.html#x2667">distributor/distributor.ui.h</a>.
429<p>Reimplemented in <a href="qsocket.html#readBlock">QSocket</a> and <a href="qsocketdevice.html#readBlock">QSocketDevice</a>.
430<h3 class=fn>Q_LONG <a name="readLine"></a>QIODevice::readLine ( char&nbsp;*&nbsp;data, Q_ULONG&nbsp;maxlen )<tt> [virtual]</tt>
431</h3>
432Reads a line of text, (or up to <em>maxlen</em> bytes if a newline isn't
433encountered) plus a terminating '&#92;0' into <em>data</em>. If there is a
434newline at the end if the line, it is not stripped.
435<p> Returns the number of bytes read including the terminating '&#92;0',
436or -1 if an error occurred.
437<p> This virtual function can be reimplemented much more efficiently
438by the most subclasses.
439<p> <p>See also <a href="#readBlock">readBlock</a>() and <a href="qtextstream.html#readLine">QTextStream::readLine</a>().
440
441<p>Reimplemented in <a href="qfile.html#readLine">QFile</a>.
442<h3 class=fn>bool <a name="reset"></a>QIODevice::reset ()
443</h3>
444
445<p> Sets the device index position to 0.
446<p> <p>See also <a href="#at">at</a>().
447
448<h3 class=fn>void <a name="resetStatus"></a>QIODevice::resetStatus ()
449</h3>
450
451<p> Sets the I/O device status to <a href="qiodevice.html#status">IO_Ok</a>.
452<p> <p>See also <a href="#status">status</a>().
453
454<h3 class=fn>void <a name="setFlags"></a>QIODevice::setFlags ( int&nbsp;flags )<tt> [protected]</tt>
455</h3>
456
457<p> Used by subclasses to set the device flags to the <em>flags</em> specified.
458
459<h3 class=fn>void <a name="setMode"></a>QIODevice::setMode ( int&nbsp;mode )<tt> [protected]</tt>
460</h3>
461
462<p> Used by subclasses to set the device mode to the <em>mode</em> specified.
463
464<h3 class=fn>void <a name="setState"></a>QIODevice::setState ( int&nbsp;state )<tt> [protected]</tt>
465</h3>
466
467<p> Used by subclasses to set the device state to the <em>state</em> specified.
468
469<h3 class=fn>void <a name="setStatus"></a>QIODevice::setStatus ( int&nbsp;s )<tt> [protected]</tt>
470</h3>
471Used by subclasses to set the device status (not state) to <em>s</em>.
472
473<h3 class=fn>void <a name="setType"></a>QIODevice::setType ( int&nbsp;type )<tt> [protected]</tt>
474</h3>
475
476<p> Used by subclasses to set the device type to the <em>type</em> specified.
477
478<h3 class=fn><a href="qiodevice.html#Offset">Offset</a> <a name="size"></a>QIODevice::size () const<tt> [pure virtual]</tt>
479</h3>
480
481<p> Virtual function that returns the size of the I/O device.
482<p> <p>See also <a href="#at">at</a>().
483
484<p>Reimplemented in <a href="qfile.html#size">QFile</a> and <a href="qsocket.html#size">QSocket</a>.
485<h3 class=fn>int <a name="state"></a>QIODevice::state () const
486</h3>
487
488<p> Returns bits OR'ed together that specify the current state.
489<p> The flags are: <tt>IO_Open</tt>.
490<p> Subclasses may define additional flags.
491
492<h3 class=fn>int <a name="status"></a>QIODevice::status () const
493</h3>
494
495<p> Returns the I/O device status.
496<p> The I/O device status returns an error code. If <a href="#open">open</a>() returns
497FALSE or <a href="#readBlock">readBlock</a>() or <a href="#writeBlock">writeBlock</a>() return -1, this function can
498be called to find out the reason why the operation failed.
499<p> <!-- index IO_Ok --><!-- index IO_ReadError --><!-- index IO_WriteError --><!-- index IO_FatalError --><!-- index IO_OpenError --><!-- index IO_ConnectError --><!-- index IO_AbortError --><!-- index IO_TimeOutError --><!-- index IO_UnspecifiedError -->
500<p> The status codes are:
501<center><table cellpadding="4" cellspacing="2" border="0">
502<tr bgcolor="#a2c511"> <th valign="top">Status code <th valign="top">Meaning
503<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qiodevice.html#status">IO_Ok</a> <td valign="top">The operation was successful.
504<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qiodevice.html#status">IO_ReadError</a> <td valign="top">Could not read from the device.
505<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qiodevice.html#status">IO_WriteError</a> <td valign="top">Could not write to the device.
506<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qiodevice.html#status">IO_FatalError</a> <td valign="top">A fatal unrecoverable error occurred.
507<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qiodevice.html#status">IO_OpenError</a> <td valign="top">Could not open the device.
508<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qiodevice.html#status">IO_ConnectError</a> <td valign="top">Could not connect to the device.
509<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qiodevice.html#status">IO_AbortError</a> <td valign="top">The operation was unexpectedly aborted.
510<tr bgcolor="#d0d0d0"> <td valign="top"><a href="qiodevice.html#status">IO_TimeOutError</a> <td valign="top">The operation timed out.
511<tr bgcolor="#f0f0f0"> <td valign="top"><a href="qiodevice.html#status">IO_UnspecifiedError</a> <td valign="top">An unspecified error happened on close.
512</table></center>
513<p> <p>See also <a href="#resetStatus">resetStatus</a>().
514
515<h3 class=fn>int <a name="ungetch"></a>QIODevice::ungetch ( int&nbsp;ch )<tt> [pure virtual]</tt>
516</h3>
517
518<p> Puts the character <em>ch</em> back into the I/O device and decrements
519the index position if it is not zero.
520<p> This function is normally called to "undo" a <a href="#getch">getch</a>() operation.
521<p> Returns <em>ch</em>, or -1 if an error occurred.
522<p> This virtual function must be reimplemented by all subclasses.
523<p> <p>See also <a href="#getch">getch</a>() and <a href="#putch">putch</a>().
524
525<p>Reimplemented in <a href="qfile.html#ungetch">QFile</a> and <a href="qsocket.html#ungetch">QSocket</a>.
526<h3 class=fn>Q_LONG <a name="writeBlock"></a>QIODevice::writeBlock ( const&nbsp;char&nbsp;*&nbsp;data, Q_ULONG&nbsp;len )<tt> [pure virtual]</tt>
527</h3>
528
529<p> Writes <em>len</em> bytes from <em>data</em> to the I/O device and returns the
530number of bytes actually written.
531<p> This function should return -1 if a fatal error occurs.
532<p> This virtual function must be reimplemented by all subclasses.
533<p> <p>See also <a href="#readBlock">readBlock</a>().
534
535<p>Example: <a href="distributor-example.html#x2668">distributor/distributor.ui.h</a>.
536<p>Reimplemented in <a href="qbuffer.html#writeBlock">QBuffer</a>, <a href="qsocket.html#writeBlock">QSocket</a>, and <a href="qsocketdevice.html#writeBlock">QSocketDevice</a>.
537<h3 class=fn>Q_LONG <a name="writeBlock-2"></a>QIODevice::writeBlock ( const&nbsp;<a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;data )
538</h3>
539This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
540<p> This convenience function is the same as calling <a href="#writeBlock">writeBlock</a>(
541data.data(), data.<a href="#size">size</a>() ).
542
543<!-- eof -->
544<hr><p>
545This file is part of the <a href="index.html">Qt toolkit</a>.
546Copyright &copy; 1995-2007
547<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
548<table width=100% cellspacing=0 border=0><tr>
549<td>Copyright &copy; 2007
550<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
551<td align=right><div align=right>Qt 3.3.8</div>
552</table></div></address></body>
553</html>
Note: See TracBrowser for help on using the repository browser.