~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qiodevice.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/io/qiodevice.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QIODevice Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QIODevice Class Reference</h1>
 
21
<p>The QIODevice class is the base interface class of all I/O devices in Qt. <a href="#details">More...</a></p>
 
22
<pre>#include &lt;QIODevice&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p>Inherits <a href="qobject.html">QObject</a>.</p>
 
24
<p>Inherited by <a href="q3socket.html">Q3Socket</a>, <a href="q3socketdevice.html">Q3SocketDevice</a>, <a href="qabstractsocket.html">QAbstractSocket</a>, <a href="qbuffer.html">QBuffer</a>, <a href="qfile.html">QFile</a>, and <a href="qprocess.html">QProcess</a>.</p>
 
25
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
 
26
<ul>
 
27
<li><a href="qiodevice-members.html">List of all members, including inherited members</a></li>
 
28
<li><a href="qiodevice-qt3.html">Qt 3 support members</a></li>
 
29
</ul>
 
30
<a name="public-types"></a>
 
31
<h3>Public Types</h3>
 
32
<ul>
 
33
<li><div class="fn"/>flags <b><a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a></b></li>
 
34
<li><div class="fn"/>enum <b><a href="qiodevice.html#OpenModeFlag-enum">OpenModeFlag</a></b> { NotOpen, ReadOnly, WriteOnly, ReadWrite, ..., Unbuffered }</li>
 
35
</ul>
 
36
<a name="public-functions"></a>
 
37
<h3>Public Functions</h3>
 
38
<ul>
 
39
<li><div class="fn"/><b><a href="qiodevice.html#QIODevice">QIODevice</a></b> ()</li>
 
40
<li><div class="fn"/><b><a href="qiodevice.html#QIODevice-2">QIODevice</a></b> ( QObject * <i>parent</i> )</li>
 
41
<li><div class="fn"/>virtual <b><a href="qiodevice.html#dtor.QIODevice">~QIODevice</a></b> ()</li>
 
42
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#atEnd">atEnd</a></b> () const</li>
 
43
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#bytesAvailable">bytesAvailable</a></b> () const</li>
 
44
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#bytesToWrite">bytesToWrite</a></b> () const</li>
 
45
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#canReadLine">canReadLine</a></b> () const</li>
 
46
<li><div class="fn"/>virtual void <b><a href="qiodevice.html#close">close</a></b> ()</li>
 
47
<li><div class="fn"/>QString <b><a href="qiodevice.html#errorString">errorString</a></b> () const</li>
 
48
<li><div class="fn"/>bool <b><a href="qiodevice.html#getChar">getChar</a></b> ( char * <i>c</i> )</li>
 
49
<li><div class="fn"/>bool <b><a href="qiodevice.html#isOpen">isOpen</a></b> () const</li>
 
50
<li><div class="fn"/>bool <b><a href="qiodevice.html#isReadable">isReadable</a></b> () const</li>
 
51
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#isSequential">isSequential</a></b> () const</li>
 
52
<li><div class="fn"/>bool <b><a href="qiodevice.html#isTextModeEnabled">isTextModeEnabled</a></b> () const</li>
 
53
<li><div class="fn"/>bool <b><a href="qiodevice.html#isWritable">isWritable</a></b> () const</li>
 
54
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#open">open</a></b> ( OpenMode <i>mode</i> )</li>
 
55
<li><div class="fn"/>OpenMode <b><a href="qiodevice.html#openMode">openMode</a></b> () const</li>
 
56
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#pos">pos</a></b> () const</li>
 
57
<li><div class="fn"/>bool <b><a href="qiodevice.html#putChar">putChar</a></b> ( char <i>c</i> )</li>
 
58
<li><div class="fn"/>qint64 <b><a href="qiodevice.html#read">read</a></b> ( char * <i>data</i>, qint64 <i>maxSize</i> )</li>
 
59
<li><div class="fn"/>QByteArray <b><a href="qiodevice.html#read-2">read</a></b> ( qint64 <i>maxSize</i> )</li>
 
60
<li><div class="fn"/>QByteArray <b><a href="qiodevice.html#readAll">readAll</a></b> ()</li>
 
61
<li><div class="fn"/>qint64 <b><a href="qiodevice.html#readLine">readLine</a></b> ( char * <i>data</i>, qint64 <i>maxSize</i> )</li>
 
62
<li><div class="fn"/>QByteArray <b><a href="qiodevice.html#readLine-2">readLine</a></b> ( qint64 <i>maxSize</i> = 0 )</li>
 
63
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#reset">reset</a></b> ()</li>
 
64
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#seek">seek</a></b> ( qint64 <i>pos</i> )</li>
 
65
<li><div class="fn"/>void <b><a href="qiodevice.html#setTextModeEnabled">setTextModeEnabled</a></b> ( bool <i>enabled</i> )</li>
 
66
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#size">size</a></b> () const</li>
 
67
<li><div class="fn"/>void <b><a href="qiodevice.html#ungetChar">ungetChar</a></b> ( char <i>c</i> )</li>
 
68
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a></b> ( int <i>msecs</i> )</li>
 
69
<li><div class="fn"/>virtual bool <b><a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a></b> ( int <i>msecs</i> )</li>
 
70
<li><div class="fn"/>qint64 <b><a href="qiodevice.html#write">write</a></b> ( const char * <i>data</i>, qint64 <i>maxSize</i> )</li>
 
71
<li><div class="fn"/>qint64 <b><a href="qiodevice.html#write-2">write</a></b> ( const QByteArray &amp; <i>byteArray</i> )</li>
 
72
</ul>
 
73
<ul>
 
74
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
75
</ul>
 
76
<a name="signals"></a>
 
77
<h3>Signals</h3>
 
78
<ul>
 
79
<li><div class="fn"/>void <b><a href="qiodevice.html#aboutToClose">aboutToClose</a></b> ()</li>
 
80
<li><div class="fn"/>void <b><a href="qiodevice.html#bytesWritten">bytesWritten</a></b> ( qint64 <i>bytes</i> )</li>
 
81
<li><div class="fn"/>void <b><a href="qiodevice.html#readyRead">readyRead</a></b> ()</li>
 
82
</ul>
 
83
<ul>
 
84
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
85
</ul>
 
86
<a name="protected-functions"></a>
 
87
<h3>Protected Functions</h3>
 
88
<ul>
 
89
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#readData">readData</a></b> ( char * <i>data</i>, qint64 <i>maxSize</i> ) = 0</li>
 
90
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#readLineData">readLineData</a></b> ( char * <i>data</i>, qint64 <i>maxSize</i> )</li>
 
91
<li><div class="fn"/>void <b><a href="qiodevice.html#setErrorString">setErrorString</a></b> ( const QString &amp; <i>str</i> )</li>
 
92
<li><div class="fn"/>void <b><a href="qiodevice.html#setOpenMode">setOpenMode</a></b> ( OpenMode <i>openMode</i> )</li>
 
93
<li><div class="fn"/>virtual qint64 <b><a href="qiodevice.html#writeData">writeData</a></b> ( const char * <i>data</i>, qint64 <i>maxSize</i> ) = 0</li>
 
94
</ul>
 
95
<ul>
 
96
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
97
</ul>
 
98
<h3>Additional Inherited Members</h3>
 
99
<ul>
 
100
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
101
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
102
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
103
</ul>
 
104
<a name="details"></a>
 
105
<hr />
 
106
<h2>Detailed Description</h2>
 
107
<p>The QIODevice class is the base interface class of all I/O devices in Qt.</p>
 
108
<p>QIODevice provides both a common implementation and an abstract interface for devices that support reading and writing of blocks of data, such as <a href="qfile.html">QFile</a>, <a href="qbuffer.html">QBuffer</a> and <a href="qtcpsocket.html">QTcpSocket</a>. QIODevice is abstract and can not be instantiated, but is it common to use the interface it defines to provide device-independent I/O features. For example, Qt's XML classes operate on a QIODevice pointer, allowing them to be used with various devices (such as files and buffers).</p>
 
109
<p>Before accessing the device, <a href="qiodevice.html#open">open</a>() must be called to set the correct <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> (such as <a href="qiodevice.html#OpenModeFlag-enum">ReadOnly</a> or <a href="qiodevice.html#OpenModeFlag-enum">ReadWrite</a>). You can then write to the device with <a href="qiodevice.html#write">write</a>() or <a href="qiodevice.html#putChar">putChar</a>(), and read by calling either <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), or <a href="qiodevice.html#readAll">readAll</a>(). Call <a href="qiodevice.html#close">close</a>() when you are done with the device.</p>
 
110
<p>QIODevice distinguishes between two types of devices: random-access devices and sequential devices.</p>
 
111
<ul>
 
112
<li>Random-access devices support seeking to arbitrary positions using <a href="qiodevice.html#seek">seek</a>(). The current position in the file is available by calling <a href="qiodevice.html#pos">pos</a>(). <a href="qfile.html">QFile</a> and <a href="qbuffer.html">QBuffer</a> are examples of random-access devices.</li>
 
113
<li>Sequential devices don't support seeking to arbitrary positions. The data must be read in one pass. Functions like <a href="qiodevice.html#pos">pos</a>(), <a href="qiodevice.html#seek">seek</a>(), and <a href="qiodevice.html#size">size</a>() don't work for sequential devices. <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qprocess.html">QProcess</a> are examples of sequential devices.</li>
 
114
</ul>
 
115
<p>You can use <a href="qiodevice.html#isSequential">isSequential</a>() to determine the type of device.</p>
 
116
<p>QIODevice emits <a href="qiodevice.html#readyRead">readyRead</a>() when new data is available for reading; for example, if new data has arrived on the network or if additional data is appended to a file that you are reading from. You can call <a href="qiodevice.html#bytesAvailable">bytesAvailable</a>() to determine the number of bytes that currently available for reading. It's common to use <a href="qiodevice.html#bytesAvailable">bytesAvailable</a>() together with the <a href="qiodevice.html#readyRead">readyRead</a>() signal when programming with asynchronous devices such as <a href="qtcpsocket.html">QTcpSocket</a>, where fragments of data can arrive at arbitrary points in time. QIODevice emits the <a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal every time a payload of data has been written to the device. Use <a href="qiodevice.html#bytesToWrite">bytesToWrite</a>() to determine the current amount of data waiting to be written.</p>
 
117
<p>Certain subclasses of QIODevice, such as <a href="qtcpsocket.html">QTcpSocket</a> and <a href="qprocess.html">QProcess</a>, are asynchronous. This means that I/O functions such as <a href="qiodevice.html#write">write</a>() or <a href="qiodevice.html#read">read</a>() always return immediately, while communication with the device itself may happen when control goes back to the event loop. QIODevice provides functions that allow you to force these operations to be performed immediately, while blocking the calling thread and without entering the event loop. This allows QIODevice subclasses to be used without an event loop, or in a separate thread:</p>
 
118
<ul>
 
119
<li><a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>() - This function suspends operation in the calling thread until new data is available for reading.</li>
 
120
<li><a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>() - This function suspends operation in the calling thread until one payload of data has been written to the device.</li>
 
121
<li>waitFor....() - Subclasses of QIODevice implement blocking functions for device-specific operations. For example, <a href="qprocess.html">QProcess</a> has a function called waitForStarted() which suspends operation in the calling thread until the process has started.</li>
 
122
</ul>
 
123
<p>Calling these functions from the main, GUI thread, may cause your user interface to freeze. Example:</p>
 
124
<pre>&nbsp;   QProcess gzip;
 
125
    gzip.start(&quot;gzip&quot;, QStringList() &lt;&lt; &quot;-c&quot;);
 
126
    if (!gzip.waitForStarted())
 
127
        return false;
 
128
 
 
129
    gzip.write(&quot;uncompressed data&quot;);
 
130
 
 
131
    QByteArray compressed;
 
132
    while (gzip.waitForReadyRead())
 
133
        compressed += gzip.readAll();</pre>
 
134
<p>By subclassing QIODevice, you can provide the same interface to your own I/O devices. Subclasses of QIODevice are only required to implement the protected <a href="qiodevice.html#readData">readData</a>() and <a href="qiodevice.html#writeData">writeData</a>() functions. QIODevice uses these functions to implement all its convenience functions, such as <a href="qiodevice.html#getChar">getChar</a>(), <a href="qiodevice.html#readLine">readLine</a>() and <a href="qiodevice.html#write">write</a>(). QIODevice also handles access control for you, so you can safely assume that the device is opened in write mode if <a href="qiodevice.html#writeData">writeData</a>() is called.</p>
 
135
<p>Some subclasses, such as <a href="qfile.html">QFile</a> and <a href="qtcpsocket.html">QTcpSocket</a>, are implemented using a memory buffer for intermediate storing of data. This reduces the number of required device accessing calls, which are often very slow. Buffering makes functions like <a href="qiodevice.html#getChar">getChar</a>() and <a href="qiodevice.html#putChar">putChar</a>() fast, as they can operate on the memory buffer instead of directly on the device itself. Certain I/O operations, however, don't work well with a buffer. For example, if several users open the same device and read it character by character, they may end up reading the same data when they meant to read a separate chunk each. For this reason, QIODevice allows you to bypass any buffering by passing the Unbuffered flag to <a href="qiodevice.html#open">open</a>(). When subclassing QIODevice, remember to bypass any buffer you may use when the device is open in Unbuffered mode.</p>
 
136
<p>See also <a href="qbuffer.html">QBuffer</a>, <a href="qfile.html">QFile</a>, and <a href="qtcpsocket.html">QTcpSocket</a>.</p>
 
137
<hr />
 
138
<h2>Member Type Documentation</h2>
 
139
<h3 class="flags"><a name="OpenModeFlag-enum"></a>enum QIODevice::OpenModeFlag<br />flags QIODevice::OpenMode</h3>
 
140
<p>This enum is used with <a href="qiodevice.html#open">open</a>() to describe the mode in which a device is opened. It is also returned by <a href="qiodevice.html#openMode">openMode</a>().</p>
 
141
<table border="1" cellpadding="2" cellspacing="1" width="100%">
 
142
<tr><th width="25%">Constant</th><th width="15%">Value</th><th width="60%">Description</th></tr>
 
143
<tr><td valign="top"><tt>QIODevice::NotOpen</tt></td><td align="center" valign="top"><tt>0x0000</tt></td><td valign="top">The device is not open.</td></tr>
 
144
<tr><td valign="top"><tt>QIODevice::ReadOnly</tt></td><td align="center" valign="top"><tt>0x0001</tt></td><td valign="top">The device is open for reading.</td></tr>
 
145
<tr><td valign="top"><tt>QIODevice::WriteOnly</tt></td><td align="center" valign="top"><tt>0x0002</tt></td><td valign="top">The device is open for writing.</td></tr>
 
146
<tr><td valign="top"><tt>QIODevice::ReadWrite</tt></td><td align="center" valign="top"><tt>ReadOnly | WriteOnly</tt></td><td valign="top">The device is open for reading and writing.</td></tr>
 
147
<tr><td valign="top"><tt>QIODevice::Append</tt></td><td align="center" valign="top"><tt>0x0004</tt></td><td valign="top">The device is opened in append mode, so that all data is written to the end of the file.</td></tr>
 
148
<tr><td valign="top"><tt>QIODevice::Truncate</tt></td><td align="center" valign="top"><tt>0x0008</tt></td><td valign="top">If possible, the device is truncated before it is opened. All earlier contents of the device are lost.</td></tr>
 
149
<tr><td valign="top"><tt>QIODevice::Text</tt></td><td align="center" valign="top"><tt>0x0010</tt></td><td valign="top">When reading lines using <a href="qiodevice.html#readLine">readLine</a>(), end-of-line terminators are translated to the local encoding.</td></tr>
 
150
<tr><td valign="top"><tt>QIODevice::Unbuffered</tt></td><td align="center" valign="top"><tt>0x0020</tt></td><td valign="top">Any buffer in the device is bypassed.</td></tr>
 
151
</table>
 
152
<p>Certain flags, such as QIODevice::Unbuffered and QIODevice::Truncate, might be meaningless for some subclasses. (For example, access to a <a href="qbuffer.html">QBuffer</a> is always unbuffered.)</p>
 
153
<p>The OpenMode type is a typedef for <a href="qflags.html">QFlags</a>&lt;OpenModeFlag&gt;. It stores an OR combination of OpenModeFlag values.</p>
 
154
<hr />
 
155
<h2>Member Function Documentation</h2>
 
156
<h3 class="fn"><a name="QIODevice"></a>QIODevice::QIODevice ()</h3>
 
157
<p>Constructs a <a href="qiodevice.html">QIODevice</a> object.</p>
 
158
<h3 class="fn"><a name="QIODevice-2"></a>QIODevice::QIODevice ( <a href="qobject.html">QObject</a> * <i>parent</i> )</h3>
 
159
<p>Constructs a <a href="qiodevice.html">QIODevice</a> object with the given <i>parent</i>.</p>
 
160
<h3 class="fn"><a name="dtor.QIODevice"></a>QIODevice::~QIODevice ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
161
<p>Destructs the <a href="qiodevice.html">QIODevice</a> object.</p>
 
162
<h3 class="fn"><a name="aboutToClose"></a>void QIODevice::aboutToClose ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
163
<p>This signal is emitted when the device is about to close. Connect this signal if you have operations that need to be performed before the device closes (e.g., if you have data in a separate buffer that needs to be written to the device).</p>
 
164
<h3 class="fn"><a name="atEnd"></a>bool QIODevice::atEnd () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
165
<p>Returns true if the current read and write position is at the end of the device (i.e. there is no more data available for reading on the device); otherwise returns false.</p>
 
166
<h3 class="fn"><a name="bytesAvailable"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::bytesAvailable () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
167
<p>Returns the number of bytes that are available for reading. This function is commonly used with sequential devices to determine the number of bytes to allocate in a buffer before reading.</p>
 
168
<h3 class="fn"><a name="bytesToWrite"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::bytesToWrite () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
169
<p>For buffered devices, this function returns the number of bytes waiting to be written. For devices with no buffer, this function returns 0.</p>
 
170
<h3 class="fn"><a name="bytesWritten"></a>void QIODevice::bytesWritten ( <a href="qtglobal.html#qint64-typedef">qint64</a> <i>bytes</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
171
<p>This signal is emitted every time a payload of data has been written to the device. The <i>bytes</i> argument is set to the number of bytes that were written in this payload.</p>
 
172
<p>bytesWritten() is not emitted recursively; if you reenter the event loop or call <a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>() inside a slot connected to the bytesWritten() signal, the signal will not be reemitted (although <a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>() may still return true).</p>
 
173
<p>See also <a href="qiodevice.html#readyRead">readyRead</a>().</p>
 
174
<h3 class="fn"><a name="canReadLine"></a>bool QIODevice::canReadLine () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
175
<p>Returns true if a complete line of data can be read from the device; otherwise returns false.</p>
 
176
<p>Note that unbuffered devices, which have no way of determining what can be read, always return false.</p>
 
177
<p>This function is often called in conjunction with the <a href="qiodevice.html#readyRead">readyRead</a>() signal.</p>
 
178
<p>See also <a href="qiodevice.html#readyRead">readyRead</a>() and <a href="qiodevice.html#readLine">readLine</a>().</p>
 
179
<h3 class="fn"><a name="close"></a>void QIODevice::close ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
180
<p>First emits <a href="qiodevice.html#aboutToClose">aboutToClose</a>(), then closes the device and sets its <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> to <a href="qiodevice.html#OpenModeFlag-enum">NotOpen</a>. The error string is also reset.</p>
 
181
<p>See also <a href="qiodevice.html#setOpenMode">setOpenMode</a>() and <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
182
<h3 class="fn"><a name="errorString"></a><a href="qstring.html">QString</a> QIODevice::errorString () const</h3>
 
183
<p>Returns a human-readable description of the last device error that occurred.</p>
 
184
<p>See also <a href="qiodevice.html#setErrorString">setErrorString</a>().</p>
 
185
<h3 class="fn"><a name="getChar"></a>bool QIODevice::getChar ( char * <i>c</i> )</h3>
 
186
<p>Reads one character from the device and stores it in <i>c</i>. If <i>c</i> is 0, the character is discarded. Returns true on success; otherwise returns false.</p>
 
187
<p>See also <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#putChar">putChar</a>(), and <a href="qiodevice.html#ungetChar">ungetChar</a>().</p>
 
188
<h3 class="fn"><a name="isOpen"></a>bool QIODevice::isOpen () const</h3>
 
189
<p>Returns true if the device is open; otherwise returns false. A device is open if it can be read from and/or written to. By default, this function returns false if <a href="qiodevice.html#openMode">openMode</a>() returns <tt>NotOpen</tt>.</p>
 
190
<p>See also <a href="qiodevice.html#openMode">openMode</a>() and <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
191
<h3 class="fn"><a name="isReadable"></a>bool QIODevice::isReadable () const</h3>
 
192
<p>Returns true if data can be read from the device; otherwise returns false. Use <a href="qiodevice.html#bytesAvailable">bytesAvailable</a>() to determine how many bytes can be read.</p>
 
193
<p>This is a convenience function which checks if the <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> of the device contains the <a href="qiodevice.html#OpenModeFlag-enum">ReadOnly</a> flag.</p>
 
194
<p>See also <a href="qiodevice.html#openMode">openMode</a>() and <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
195
<h3 class="fn"><a name="isSequential"></a>bool QIODevice::isSequential () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
196
<p>Returns true if this device is sequential; otherwise returns false.</p>
 
197
<p>Sequential devices, as opposed to a random-access devices, have no concept of a start, an end, a size, or a current position, and they do not support seeking. You can only read from the device when it reports that data is available. The most common example of a sequential device is a network socket. On Unix, special files such as /dev/zero and fifo pipes are sequential.</p>
 
198
<p>Regular files, on the other hand, do support random access. They have both a size and a current position, and they also support seeking backwards and forwards in the data stream. Regular files are non-sequential.</p>
 
199
<p>See also <a href="qiodevice.html#bytesAvailable">bytesAvailable</a>().</p>
 
200
<h3 class="fn"><a name="isTextModeEnabled"></a>bool QIODevice::isTextModeEnabled () const</h3>
 
201
<p>Returns true if the <a href="qiodevice.html#OpenModeFlag-enum">Text</a> flag is enabled; otherwise returns false.</p>
 
202
<p>See also <a href="qiodevice.html#setTextModeEnabled">setTextModeEnabled</a>().</p>
 
203
<h3 class="fn"><a name="isWritable"></a>bool QIODevice::isWritable () const</h3>
 
204
<p>Returns true if data can be written to the device; otherwise returns false.</p>
 
205
<p>This is a convenience function which checks if the <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> of the device contains the <a href="qiodevice.html#OpenModeFlag-enum">WriteOnly</a> flag.</p>
 
206
<p>See also <a href="qiodevice.html#openMode">openMode</a>() and <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
207
<h3 class="fn"><a name="open"></a>bool QIODevice::open ( <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> <i>mode</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
208
<p>Opens the device and sets its <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> to <i>mode</i>.</p>
 
209
<p>See also <a href="qiodevice.html#openMode">openMode</a>() and <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
210
<h3 class="fn"><a name="openMode"></a><a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> QIODevice::openMode () const</h3>
 
211
<p>Returns the mode in which the device has been opened; i.e. <a href="qiodevice.html#OpenModeFlag-enum">ReadOnly</a> or <a href="qiodevice.html#OpenModeFlag-enum">WriteOnly</a>.</p>
 
212
<p>See also <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
213
<h3 class="fn"><a name="pos"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::pos () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
214
<p>For random-access devices, this function returns the position that data is written to or read from. For sequential devices or closed devices, where there is no concept of a &quot;current position&quot;, 0 is returned.</p>
 
215
<p>See also <a href="qiodevice.html#isSequential">isSequential</a>() and <a href="qiodevice.html#seek">seek</a>().</p>
 
216
<h3 class="fn"><a name="putChar"></a>bool QIODevice::putChar ( char <i>c</i> )</h3>
 
217
<p>Writes the character <i>c</i> to the device. Returns true on success; otherwise returns false.</p>
 
218
<p>See also <a href="qiodevice.html#write">write</a>(), <a href="qiodevice.html#getChar">getChar</a>(), and <a href="qiodevice.html#ungetChar">ungetChar</a>().</p>
 
219
<h3 class="fn"><a name="read"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::read ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )</h3>
 
220
<p>Reads at most <i>maxSize</i> bytes from the device into <i>data</i>, and returns the number of bytes read. If an error occurs, such as when attempting to read from a device opened in <a href="qiodevice.html#OpenModeFlag-enum">WriteOnly</a> mode, this function returns -1.</p>
 
221
<p>0 is returned when no more data is available for reading.</p>
 
222
<p>See also <a href="qiodevice.html#readData">readData</a>(), <a href="qiodevice.html#readLine">readLine</a>(), and <a href="qiodevice.html#write">write</a>().</p>
 
223
<h3 class="fn"><a name="read-2"></a><a href="qbytearray.html">QByteArray</a> QIODevice::read ( <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )</h3>
 
224
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
225
<p>Reads at most <i>maxSize</i> bytes from the device, and returns the data read as a <a href="qbytearray.html">QByteArray</a>.</p>
 
226
<p>This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.</p>
 
227
<h3 class="fn"><a name="readAll"></a><a href="qbytearray.html">QByteArray</a> QIODevice::readAll ()</h3>
 
228
<p>Reads all available data from the device, and returns it as a <a href="qbytearray.html">QByteArray</a>.</p>
 
229
<p>This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.</p>
 
230
<h3 class="fn"><a name="readData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::readData ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )&nbsp;&nbsp;<tt> [pure virtual protected]</tt></h3>
 
231
<p>Reads up to <i>maxSize</i> bytes from the device into <i>data</i>, and returns the number of bytes read or -1 if an error occurred.</p>
 
232
<p>This function is called by <a href="qiodevice.html">QIODevice</a>. Reimplement this function when creating a subclass of <a href="qiodevice.html">QIODevice</a>.</p>
 
233
<p>See also <a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), and <a href="qiodevice.html#writeData">writeData</a>().</p>
 
234
<h3 class="fn"><a name="readLine"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::readLine ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )</h3>
 
235
<p>This function reads a line of ASCII characters from the device, up to a maximum of <i>maxSize</i> bytes, stores the characters in <i>data</i>, and returns the number of bytes read. If an error occurred, -1 is returned.</p>
 
236
<p>If there is room in the buffer (i.e. the line read is shorter than <i>maxSize</i> characters), a '\0' byte is appended to <i>data</i>.</p>
 
237
<p>Data is read until either of the following conditions are met:</p>
 
238
<ul>
 
239
<li>The first '\n' character is read.</li>
 
240
<li><i>maxSize</i> bytes are read.</li>
 
241
<li>The end of the device data is detected.</li>
 
242
</ul>
 
243
<p>For example, the following code reads a line of characters from a file:</p>
 
244
<pre>&nbsp;   QFile file(&quot;box.txt&quot;);
 
245
    if (file.open(QFile::ReadOnly)) {
 
246
        char buf[1024];
 
247
        qint64 lineLength = file.readLine(buf, sizeof(buf));
 
248
        if (lineLength != -1) {
 
249
            // the line is available in buf
 
250
        }
 
251
    }</pre>
 
252
<p>If the '\n' character is the 1024th character read then it will be inserted into the buffer; if it occurs after the 1024 character then it is not read.</p>
 
253
<p>This function calls <a href="qiodevice.html#readLineData">readLineData</a>(), which is implemented using repeated calls to <a href="qiodevice.html#getChar">getChar</a>(). You can provide a more efficient implementation by reimplementing <a href="qiodevice.html#readLineData">readLineData</a>() in your own subclass.</p>
 
254
<p>See also <a href="qiodevice.html#getChar">getChar</a>(), <a href="qiodevice.html#read">read</a>(), and <a href="qiodevice.html#write">write</a>().</p>
 
255
<h3 class="fn"><a name="readLine-2"></a><a href="qbytearray.html">QByteArray</a> QIODevice::readLine ( <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> = 0 )</h3>
 
256
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
257
<p>Reads a line from the device, but no more than <i>maxSize</i> characters, and returns the result as a <a href="qbytearray.html">QByteArray</a>.</p>
 
258
<p>This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.</p>
 
259
<h3 class="fn"><a name="readLineData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::readLineData ( char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )&nbsp;&nbsp;<tt> [virtual protected]</tt></h3>
 
260
<p>Reads up to <i>maxSize</i> characters into <i>data</i> and returns the number of characters read.</p>
 
261
<p>This function is called by <a href="qiodevice.html#readLine">readLine</a>(), and provides its base implementation, using <a href="qiodevice.html#getChar">getChar</a>(). Buffered devices can improve the performance of <a href="qiodevice.html#readLine">readLine</a>() by reimplementing this function.</p>
 
262
<p>When reimplementing this function, keep in mind that you must handle the <a href="qiodevice.html#OpenModeFlag-enum">Text</a> flag which translates end-of-line characters.</p>
 
263
<h3 class="fn"><a name="readyRead"></a>void QIODevice::readyRead ()&nbsp;&nbsp;<tt> [signal]</tt></h3>
 
264
<p>This signal is emitted once every time new data is available for reading from the device. It will only be emitted again once new data is available, such as when a new payload of network data has arrived on your network socket, or when a new block of data has been appended to your file.</p>
 
265
<p>readyRead() is not emitted recursively; if you reenter the event loop or call <a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>() inside a slot connected to the readyRead() signal, the signal will not be reemitted (although <a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>() may still return true).</p>
 
266
<p>See also <a href="qiodevice.html#bytesWritten">bytesWritten</a>().</p>
 
267
<h3 class="fn"><a name="reset"></a>bool QIODevice::reset ()&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
268
<p>Seeks to the start of input for random-access devices. Returns true on success; otherwise returns false (for example, if the device is not open).</p>
 
269
<p>See also <a href="qiodevice.html#seek">seek</a>().</p>
 
270
<h3 class="fn"><a name="seek"></a>bool QIODevice::seek ( <a href="qtglobal.html#qint64-typedef">qint64</a> <i>pos</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
271
<p>For random-access devices, this function sets the current position to <i>pos</i>, returning true on success, or false if an error occurred. For sequential devices, the default behavior is to do nothing and return false.</p>
 
272
<p>When subclassing <a href="qiodevice.html">QIODevice</a>, you must call QIODevice::seek() at the start of your function to ensure integrity with <a href="qiodevice.html">QIODevice</a>'s built-in ungetbuffer. The base implementation always returns true.</p>
 
273
<p>See also <a href="qiodevice.html#pos">pos</a>().</p>
 
274
<h3 class="fn"><a name="setErrorString"></a>void QIODevice::setErrorString ( const <a href="qstring.html">QString</a> &amp; <i>str</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
275
<p>Sets the human readable description of the last device error that occurred to <i>str</i>.</p>
 
276
<p>See also <a href="qiodevice.html#errorString">errorString</a>().</p>
 
277
<h3 class="fn"><a name="setOpenMode"></a>void QIODevice::setOpenMode ( <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> <i>openMode</i> )&nbsp;&nbsp;<tt> [protected]</tt></h3>
 
278
<p>Sets the <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a> of the device to <i>openMode</i>. Reimplement this function to set the open mode when reimplementing <a href="qiodevice.html#open">open</a>().</p>
 
279
<p>See also <a href="qiodevice.html#openMode">openMode</a>() and <a href="qiodevice.html#OpenModeFlag-enum">OpenMode</a>.</p>
 
280
<h3 class="fn"><a name="setTextModeEnabled"></a>void QIODevice::setTextModeEnabled ( bool <i>enabled</i> )</h3>
 
281
<p>If <i>enabled</i> is true, this function sets the <a href="qiodevice.html#OpenModeFlag-enum">Text</a> flag on the device; otherwise the <a href="qiodevice.html#OpenModeFlag-enum">Text</a> flag is removed. This feature is useful for classes that provide custom end-of-line handling on a <a href="qiodevice.html">QIODevice</a>.</p>
 
282
<p>See also <a href="qiodevice.html#open">open</a>() and <a href="qiodevice.html#setOpenMode">setOpenMode</a>().</p>
 
283
<h3 class="fn"><a name="size"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::size () const&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
284
<p>For open random-access devices, this function returns the size of the device. For open sequential devices, <a href="qiodevice.html#bytesAvailable">bytesAvailable</a>() is returned.</p>
 
285
<p>If the device is closed, the size returned will not reflect the actual size of the device.</p>
 
286
<h3 class="fn"><a name="ungetChar"></a>void QIODevice::ungetChar ( char <i>c</i> )</h3>
 
287
<p>Puts the character <i>c</i> back into the device, and decrements the current position unless the position is 0. This function is usually called to &quot;undo&quot; a <a href="qiodevice.html#getChar">getChar</a>() operation, such as when writing a backtracking parser.</p>
 
288
<p>If <i>c</i> was not previously read from the device, the behavior is undefined.</p>
 
289
<h3 class="fn"><a name="waitForBytesWritten"></a>bool QIODevice::waitForBytesWritten ( int <i>msecs</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
290
<p>For buffered devices, this function waits until a payload of buffered written data has been written to the device and the <a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal has been emitted, or until <i>msecs</i> milliseconds have passed. If msecs is -1, this function will not time out. For unbuffered devices, it returns immediately.</p>
 
291
<p>Returns true if a payload of data was written to the device; otherwise returns false (i.e. if the operation timed out, or if an error occurred).</p>
 
292
<p>This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.</p>
 
293
<p>If called from within a slot connected to the <a href="qiodevice.html#bytesWritten">bytesWritten</a>() signal, <a href="qiodevice.html#bytesWritten">bytesWritten</a>() will not be reemitted.</p>
 
294
<p><b>Warning:</b> Calling this function from the main (GUI) thread might cause your user interface to freeze.</p>
 
295
<p>See also <a href="qiodevice.html#waitForReadyRead">waitForReadyRead</a>().</p>
 
296
<h3 class="fn"><a name="waitForReadyRead"></a>bool QIODevice::waitForReadyRead ( int <i>msecs</i> )&nbsp;&nbsp;<tt> [virtual]</tt></h3>
 
297
<p>Blocks until data is available for reading and the <a href="qiodevice.html#readyRead">readyRead</a>() signal has been emitted, or until <i>msecs</i> milliseconds have passed. If msecs is -1, this function will not time out.</p>
 
298
<p>Returns true if data is available for reading; otherwise returns false (if the operation timed out or if an error occurred).</p>
 
299
<p>This function can operate without an event loop. It is useful when writing non-GUI applications and when performing I/O operations in a non-GUI thread.</p>
 
300
<p>If called from within a slot connected to the <a href="qiodevice.html#readyRead">readyRead</a>() signal, <a href="qiodevice.html#readyRead">readyRead</a>() will not be reemitted.</p>
 
301
<p><b>Warning:</b> Calling this function from the main (GUI) thread might cause your user interface to freeze.</p>
 
302
<p>See also <a href="qiodevice.html#waitForBytesWritten">waitForBytesWritten</a>().</p>
 
303
<h3 class="fn"><a name="write"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::write ( const char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )</h3>
 
304
<p>Writes at most <i>maxSize</i> bytes of data from <i>data</i> to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.</p>
 
305
<p>See also <a href="qiodevice.html#read">read</a>() and <a href="qiodevice.html#writeData">writeData</a>().</p>
 
306
<h3 class="fn"><a name="write-2"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::write ( const <a href="qbytearray.html">QByteArray</a> &amp; <i>byteArray</i> )</h3>
 
307
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
308
<p>Writes the content of <i>byteArray</i> to the device. Returns the number of bytes that were actually written, or -1 if an error occurred.</p>
 
309
<p>See also <a href="qiodevice.html#read">read</a>() and <a href="qiodevice.html#writeData">writeData</a>().</p>
 
310
<h3 class="fn"><a name="writeData"></a><a href="qtglobal.html#qint64-typedef">qint64</a> QIODevice::writeData ( const char * <i>data</i>, <a href="qtglobal.html#qint64-typedef">qint64</a> <i>maxSize</i> )&nbsp;&nbsp;<tt> [pure virtual protected]</tt></h3>
 
311
<p>Writes up to <i>maxSize</i> bytes from <i>data</i> to the device. Returns the number of bytes written, or -1 if an error occurred.</p>
 
312
<p>This function is called by <a href="qiodevice.html">QIODevice</a>. Reimplement this function when creating a subclass of <a href="qiodevice.html">QIODevice</a>.</p>
 
313
<p>See also <a href="qiodevice.html#read">read</a>() and <a href="qiodevice.html#write">write</a>().</p>
 
314
<p /><address><hr /><div align="center">
 
315
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
316
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
317
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
318
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
319
</tr></table></div></address></body>
 
320
</html>