summaryrefslogtreecommitdiffstats
path: root/doc/man/man3/tqiodevice.3qt
blob: c428be7dd7f466ce8b9ca76ffe64a36d36982ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
'\" t
.TH QIODevice 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA.  All rights reserved.  See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QIODevice \- The base class of I/O devices
.SH SYNOPSIS
All the functions in this class are reentrant when TQt is built with thread support.</p>
.PP
\fC#include <ntqiodevice.h>\fR
.PP
Inherited by QBuffer, QFile, QSocket, and QSocketDevice.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "typedef TQ_ULONG \fBOffset\fR"
.br
.ti -1c
.BI "\fBQIODevice\fR ()"
.br
.ti -1c
.BI "virtual \fB~QIODevice\fR ()"
.br
.ti -1c
.BI "int \fBflags\fR () const"
.br
.ti -1c
.BI "int \fBmode\fR () const"
.br
.ti -1c
.BI "int \fBstate\fR () const"
.br
.ti -1c
.BI "bool \fBisDirectAccess\fR () const"
.br
.ti -1c
.BI "bool \fBisSequentialAccess\fR () const"
.br
.ti -1c
.BI "bool \fBisCombinedAccess\fR () const"
.br
.ti -1c
.BI "bool \fBisBuffered\fR () const"
.br
.ti -1c
.BI "bool \fBisRaw\fR () const"
.br
.ti -1c
.BI "bool \fBisSynchronous\fR () const"
.br
.ti -1c
.BI "bool \fBisAsynchronous\fR () const"
.br
.ti -1c
.BI "bool \fBisTranslated\fR () const"
.br
.ti -1c
.BI "bool \fBisReadable\fR () const"
.br
.ti -1c
.BI "bool \fBisWritable\fR () const"
.br
.ti -1c
.BI "bool \fBisReadWrite\fR () const"
.br
.ti -1c
.BI "bool \fBisInactive\fR () const"
.br
.ti -1c
.BI "bool \fBisOpen\fR () const"
.br
.ti -1c
.BI "int \fBstatus\fR () const"
.br
.ti -1c
.BI "void \fBresetStatus\fR ()"
.br
.ti -1c
.BI "virtual bool \fBopen\fR ( int mode ) = 0"
.br
.ti -1c
.BI "virtual void \fBclose\fR () = 0"
.br
.ti -1c
.BI "virtual void \fBflush\fR () = 0"
.br
.ti -1c
.BI "virtual Offset \fBsize\fR () const = 0"
.br
.ti -1c
.BI "virtual Offset \fBat\fR () const"
.br
.ti -1c
.BI "virtual bool \fBat\fR ( Offset pos )"
.br
.ti -1c
.BI "virtual bool \fBatEnd\fR () const"
.br
.ti -1c
.BI "bool \fBreset\fR ()"
.br
.ti -1c
.BI "virtual TQ_LONG \fBreadBlock\fR ( char * data, TQ_ULONG maxlen ) = 0"
.br
.ti -1c
.BI "virtual TQ_LONG \fBwriteBlock\fR ( const char * data, TQ_ULONG len ) = 0"
.br
.ti -1c
.BI "virtual TQ_LONG \fBreadLine\fR ( char * data, TQ_ULONG maxlen )"
.br
.ti -1c
.BI "TQ_LONG \fBwriteBlock\fR ( const QByteArray & data )"
.br
.ti -1c
.BI "virtual QByteArray \fBreadAll\fR ()"
.br
.ti -1c
.BI "virtual int \fBgetch\fR () = 0"
.br
.ti -1c
.BI "virtual int \fBputch\fR ( int ch ) = 0"
.br
.ti -1c
.BI "virtual int \fBungetch\fR ( int ch ) = 0"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "void \fBsetFlags\fR ( int flags )"
.br
.ti -1c
.BI "void \fBsetType\fR ( int type )"
.br
.ti -1c
.BI "void \fBsetMode\fR ( int mode )"
.br
.ti -1c
.BI "void \fBsetState\fR ( int state )"
.br
.ti -1c
.BI "void \fBsetStatus\fR ( int s )"
.br
.in -1c
.SH DESCRIPTION
The QIODevice class is the base class of I/O devices.
.PP
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.
.PP
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.
.PP
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:
.IP
.TP
open() opens a device for reading and/or writing, depending on the mode argument.
.IP
.TP
close() closes the device and tidies up (e.g. flushes buffered data)
.IP
.TP
readBlock() reads a block of data from the device.
.IP
.TP
writeBlock() writes a block of data to the device.
.IP
.TP
readLine() reads a line (of text, usually) from the device.
.IP
.TP
flush() ensures that all buffered data are written to the real device.
.IP
.PP
There are also some other, less used, action functions:
.IP
.TP
getch() reads a single character.
.IP
.TP
ungetch() forgets the last call to getch(), if possible.
.IP
.TP
putch() writes a single character.
.IP
.TP
size() returns the size of the device, if there is one.
.IP
.TP
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.
.IP
.TP
atEnd() indicates whether there is more to read, if this is meaningful for this device.
.IP
.TP
reset() moves the read/write pointer to the start of the device, if that is possible for this device.
.IP
.PP
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:
.IP
.TP
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.
.IP
.TP
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().)
.IP
.TP
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.
.IP
.TP
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().)
.IP
.TP
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().)
.IP
.TP
Finally, isOpen() returns TRUE if the device is open, i.e. after an open() call.
.IP
.PP
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:
.PP
.nf
.br
    class MyDevice : public QIODevice
.br
    {
.br
    public:
.br
        MyDevice();
.br
        ~MyDevice();
.br
.br
        bool open( int mode );
.br
        void close();
.br
        void flush();
.br
.br
        uint size() const;
.br
        int  at() const;        // non-pure virtual
.br
        bool at( int );         // non-pure virtual
.br
        bool atEnd() const;     // non-pure virtual
.br
.br
        int readBlock( char *data, uint maxlen );
.br
        int writeBlock( const char *data, uint len );
.br
        int readLine( char *data, uint maxlen );
.br
.br
        int getch();
.br
        int putch( int );
.br
        int ungetch( int );
.br
    };
.br
.fi
.PP
The three non-pure virtual functions need not be reimplemented for sequential devices.
.PP
See also QDataStream, QTextStream, and Input/Output and Networking.
.SS "Member Type Documentation"
.SH "QIODevice::Offset"
The offset within the device.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QIODevice::QIODevice ()"
Constructs an I/O device.
.SH "QIODevice::~QIODevice ()\fC [virtual]\fR"
Destroys the I/O device.
.SH "Offset QIODevice::at () const\fC [virtual]\fR"
Virtual function that returns the current I/O device position.
.PP
This is the position of the data read/write head of the I/O device.
.PP
See also size().
.PP
Example: distributor/distributor.ui.h.
.PP
Reimplemented in QSocket.
.SH "bool QIODevice::at ( Offset pos )\fC [virtual]\fR"
Virtual function that sets the I/O device position to \fIpos\fR. Returns TRUE if the position was successfully set, i.e. \fIpos\fR is within range and the seek was successful; otherwise returns FALSE.
.PP
See also size().
.PP
Reimplemented in QSocket.
.SH "bool QIODevice::atEnd () const\fC [virtual]\fR"
Virtual function that returns TRUE if the I/O device position is at the end of the input; otherwise returns FALSE.
.PP
Reimplemented in QFile and QSocket.
.SH "void QIODevice::close ()\fC [pure virtual]\fR"
Closes the I/O device.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also open().
.PP
Example: grapher/grapher.cpp.
.PP
Reimplemented in QFile and QSocket.
.SH "int QIODevice::flags () const"
Returns the current I/O device flags setting.
.PP
Flags consists of mode flags and state flags.
.PP
See also mode() and state().
.SH "void QIODevice::flush ()\fC [pure virtual]\fR"
Flushes an open I/O device.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
Reimplemented in QFile and QSocket.
.SH "int QIODevice::getch ()\fC [pure virtual]\fR"
Reads a single byte/character from the I/O device.
.PP
Returns the byte/character read, or -1 if the end of the I/O device has been reached.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also putch() and ungetch().
.PP
Reimplemented in QFile and QSocket.
.SH "bool QIODevice::isAsynchronous () const"
Returns TRUE if the device is an asynchronous device; otherwise returns FALSE, i.e. if the device is a synchronous device.
.PP
This mode is currently not in use.
.PP
See also isSynchronous().
.SH "bool QIODevice::isBuffered () const"
Returns TRUE if the I/O device is a buffered device; otherwise returns FALSE, i.e. the device is a raw device.
.PP
See also isRaw().
.SH "bool QIODevice::isCombinedAccess () const"
Returns TRUE if the I/O device is a combined access (both direct and sequential) device; otherwise returns FALSE.
.PP
This access method is currently not in use.
.SH "bool QIODevice::isDirectAccess () const"
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.
.PP
See also isSequentialAccess().
.SH "bool QIODevice::isInactive () const"
Returns TRUE if the I/O device state is 0, i.e. the device is not open; otherwise returns FALSE.
.PP
See also isOpen().
.SH "bool QIODevice::isOpen () const"
Returns TRUE if the I/O device has been opened; otherwise returns FALSE.
.PP
See also isInactive().
.PP
Example: network/networkprotocol/nntp.cpp.
.SH "bool QIODevice::isRaw () const"
Returns TRUE if the device is a raw device; otherwise returns FALSE, i.e. if the device is a buffered device.
.PP
See also isBuffered().
.SH "bool QIODevice::isReadWrite () const"
Returns TRUE if the I/O device was opened using IO_ReadWrite mode; otherwise returns FALSE.
.PP
See also isReadable() and isWritable().
.SH "bool QIODevice::isReadable () const"
Returns TRUE if the I/O device was opened using IO_ReadOnly or IO_ReadWrite mode; otherwise returns FALSE.
.PP
See also isWritable() and isReadWrite().
.SH "bool QIODevice::isSequentialAccess () const"
Returns TRUE if the device is a sequential access device; otherwise returns FALSE, i.e. if the device is a direct access device.
.PP
Operations involving size() and at(int) are not valid on sequential devices.
.PP
See also isDirectAccess().
.SH "bool QIODevice::isSynchronous () const"
Returns TRUE if the I/O device is a synchronous device; otherwise returns FALSE, i.e. the device is an asynchronous device.
.PP
See also isAsynchronous().
.SH "bool QIODevice::isTranslated () const"
Returns TRUE if the I/O device translates carriage-return and linefeed characters; otherwise returns FALSE.
.PP
A QFile is translated if it is opened with the IO_Translate mode flag.
.SH "bool QIODevice::isWritable () const"
Returns TRUE if the I/O device was opened using IO_WriteOnly or IO_ReadWrite mode; otherwise returns FALSE.
.PP
See also isReadable() and isReadWrite().
.SH "int QIODevice::mode () const"
Returns bits OR'ed together that specify the current operation mode.
.PP
These are the flags that were given to the open() function.
.PP
The flags are IO_ReadOnly, IO_WriteOnly, IO_ReadWrite, IO_Append, IO_Truncate and IO_Translate.
.SH "bool QIODevice::open ( int mode )\fC [pure virtual]\fR"
Opens the I/O device using the specified \fImode\fR. Returns TRUE if the device was successfully opened; otherwise returns FALSE.
.PP
The mode parameter \fImode\fR must be an OR'ed combination of the following flags. <center>.nf
.TS
l - l. 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
.TE
.fi
</center>
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also close().
.PP
Example: grapher/grapher.cpp.
.PP
Reimplemented in QFile and QSocket.
.SH "int QIODevice::putch ( int ch )\fC [pure virtual]\fR"
Writes the character \fIch\fR to the I/O device.
.PP
Returns \fIch\fR, or -1 if an error occurred.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also getch() and ungetch().
.PP
Example: grapher/grapher.cpp.
.PP
Reimplemented in QFile and QSocket.
.SH "QByteArray QIODevice::readAll ()\fC [virtual]\fR"
This convenience function returns all of the remaining data in the device.
.SH "TQ_LONG QIODevice::readBlock ( char * data, TQ_ULONG maxlen )\fC [pure virtual]\fR"
Reads at most \fImaxlen\fR bytes from the I/O device into \fIdata\fR and returns the number of bytes actually read.
.PP
This function should return -1 if a fatal error occurs and should return 0 if there are no bytes to read.
.PP
The device must be opened for reading, and \fIdata\fR must not be 0.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also writeBlock(), isOpen(), and isReadable().
.PP
Example: distributor/distributor.ui.h.
.PP
Reimplemented in QSocket and QSocketDevice.
.SH "TQ_LONG QIODevice::readLine ( char * data, TQ_ULONG maxlen )\fC [virtual]\fR"
Reads a line of text, (or up to \fImaxlen\fR bytes if a newline isn't encountered) plus a terminating '&#92;0' into \fIdata\fR. If there is a newline at the end if the line, it is not stripped.
.PP
Returns the number of bytes read including the terminating '&#92;0', or -1 if an error occurred.
.PP
This virtual function can be reimplemented much more efficiently by the most subclasses.
.PP
See also readBlock() and QTextStream::readLine().
.PP
Reimplemented in QFile.
.SH "bool QIODevice::reset ()"
Sets the device index position to 0.
.PP
See also at().
.SH "void QIODevice::resetStatus ()"
Sets the I/O device status to IO_Ok.
.PP
See also status().
.SH "void QIODevice::setFlags ( int flags )\fC [protected]\fR"
Used by subclasses to set the device flags to the \fIflags\fR specified.
.SH "void QIODevice::setMode ( int mode )\fC [protected]\fR"
Used by subclasses to set the device mode to the \fImode\fR specified.
.SH "void QIODevice::setState ( int state )\fC [protected]\fR"
Used by subclasses to set the device state to the \fIstate\fR specified.
.SH "void QIODevice::setStatus ( int s )\fC [protected]\fR"
Used by subclasses to set the device status (not state) to \fIs\fR.
.SH "void QIODevice::setType ( int type )\fC [protected]\fR"
Used by subclasses to set the device type to the \fItype\fR specified.
.SH "Offset QIODevice::size () const\fC [pure virtual]\fR"
Virtual function that returns the size of the I/O device.
.PP
See also at().
.PP
Reimplemented in QFile and QSocket.
.SH "int QIODevice::state () const"
Returns bits OR'ed together that specify the current state.
.PP
The flags are: \fCIO_Open\fR.
.PP
Subclasses may define additional flags.
.SH "int QIODevice::status () const"
Returns the I/O device status.
.PP
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.
.PP

.PP
The status codes are: <center>.nf
.TS
l - l. 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
.TE
.fi
</center>
.PP
See also resetStatus().
.SH "int QIODevice::ungetch ( int ch )\fC [pure virtual]\fR"
Puts the character \fIch\fR back into the I/O device and decrements the index position if it is not zero.
.PP
This function is normally called to "undo" a getch() operation.
.PP
Returns \fIch\fR, or -1 if an error occurred.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also getch() and putch().
.PP
Reimplemented in QFile and QSocket.
.SH "TQ_LONG QIODevice::writeBlock ( const char * data, TQ_ULONG len )\fC [pure virtual]\fR"
Writes \fIlen\fR bytes from \fIdata\fR to the I/O device and returns the number of bytes actually written.
.PP
This function should return -1 if a fatal error occurs.
.PP
This virtual function must be reimplemented by all subclasses.
.PP
See also readBlock().
.PP
Example: distributor/distributor.ui.h.
.PP
Reimplemented in QBuffer, QSocket, and QSocketDevice.
.SH "TQ_LONG QIODevice::writeBlock ( const QByteArray & data )"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This convenience function is the same as calling writeBlock(
data.data(), data.size() ).

.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqiodevice.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com.  See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech. 
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqiodevice.3qt) and the Qt
version (3.3.8).