source: trunk/doc/html/qdatastream.html@ 190

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

reference documentation added

File size: 33.4 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/qdatastream.cpp:51 -->
3<html>
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
6<title>QDataStream 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>QDataStream Class Reference</h1>
33
34<p>The QDataStream class provides serialization of binary data
35to a QIODevice.
36<a href="#details">More...</a>
37<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
38<p><tt>#include &lt;<a href="qdatastream-h.html">qdatastream.h</a>&gt;</tt>
39<p><a href="qdatastream-members.html">List of all member functions.</a>
40<h2>Public Members</h2>
41<ul>
42<li class=fn><a href="#QDataStream"><b>QDataStream</b></a> ()</li>
43<li class=fn><a href="#QDataStream-2"><b>QDataStream</b></a> ( QIODevice&nbsp;*&nbsp;d )</li>
44<li class=fn><a href="#QDataStream-3"><b>QDataStream</b></a> ( QByteArray&nbsp;a, int&nbsp;mode )</li>
45<li class=fn>virtual <a href="#~QDataStream"><b>~QDataStream</b></a> ()</li>
46<li class=fn>QIODevice * <a href="#device"><b>device</b></a> () const</li>
47<li class=fn>void <a href="#setDevice"><b>setDevice</b></a> ( QIODevice&nbsp;*&nbsp;d )</li>
48<li class=fn>void <a href="#unsetDevice"><b>unsetDevice</b></a> ()</li>
49<li class=fn>bool <a href="#atEnd"><b>atEnd</b></a> () const</li>
50<li class=fn>bool eof () const &nbsp;<em>(obsolete)</em></li>
51<li class=fn>enum <a href="#ByteOrder-enum"><b>ByteOrder</b></a> { BigEndian, LittleEndian }</li>
52<li class=fn>int <a href="#byteOrder"><b>byteOrder</b></a> () const</li>
53<li class=fn>void <a href="#setByteOrder"><b>setByteOrder</b></a> ( int&nbsp;bo )</li>
54<li class=fn>bool <a href="#isPrintableData"><b>isPrintableData</b></a> () const</li>
55<li class=fn>void <a href="#setPrintableData"><b>setPrintableData</b></a> ( bool&nbsp;enable )</li>
56<li class=fn>int <a href="#version"><b>version</b></a> () const</li>
57<li class=fn>void <a href="#setVersion"><b>setVersion</b></a> ( int&nbsp;v )</li>
58<li class=fn>QDataStream &amp; <a href="#operator-gt-gt"><b>operator&gt;&gt;</b></a> ( Q_INT8&nbsp;&amp;&nbsp;i )</li>
59<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-2"><b>operator&gt;&gt;</b></a> ( Q_UINT8&nbsp;&amp;&nbsp;i )</li>
60<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-3"><b>operator&gt;&gt;</b></a> ( Q_INT16&nbsp;&amp;&nbsp;i )</li>
61<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-4"><b>operator&gt;&gt;</b></a> ( Q_UINT16&nbsp;&amp;&nbsp;i )</li>
62<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-5"><b>operator&gt;&gt;</b></a> ( Q_INT32&nbsp;&amp;&nbsp;i )</li>
63<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-6"><b>operator&gt;&gt;</b></a> ( Q_UINT32&nbsp;&amp;&nbsp;i )</li>
64<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-7"><b>operator&gt;&gt;</b></a> ( Q_INT64&nbsp;&amp;&nbsp;i )</li>
65<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-8"><b>operator&gt;&gt;</b></a> ( Q_UINT64&nbsp;&amp;&nbsp;i )</li>
66<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-9"><b>operator&gt;&gt;</b></a> ( Q_LONG&nbsp;&amp;&nbsp;i )</li>
67<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-a"><b>operator&gt;&gt;</b></a> ( Q_ULONG&nbsp;&amp;&nbsp;i )</li>
68<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-b"><b>operator&gt;&gt;</b></a> ( float&nbsp;&amp;&nbsp;f )</li>
69<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-c"><b>operator&gt;&gt;</b></a> ( double&nbsp;&amp;&nbsp;f )</li>
70<li class=fn>QDataStream &amp; <a href="#operator-gt-gt-d"><b>operator&gt;&gt;</b></a> ( char&nbsp;*&amp;&nbsp;s )</li>
71<li class=fn>QDataStream &amp; <a href="#operator-lt-lt"><b>operator&lt;&lt;</b></a> ( Q_INT8&nbsp;i )</li>
72<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-2"><b>operator&lt;&lt;</b></a> ( Q_UINT8&nbsp;i )</li>
73<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-3"><b>operator&lt;&lt;</b></a> ( Q_INT16&nbsp;i )</li>
74<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-4"><b>operator&lt;&lt;</b></a> ( Q_UINT16&nbsp;i )</li>
75<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-5"><b>operator&lt;&lt;</b></a> ( Q_INT32&nbsp;i )</li>
76<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-6"><b>operator&lt;&lt;</b></a> ( Q_UINT32&nbsp;i )</li>
77<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-7"><b>operator&lt;&lt;</b></a> ( Q_INT64&nbsp;i )</li>
78<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-8"><b>operator&lt;&lt;</b></a> ( Q_UINT64&nbsp;i )</li>
79<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-9"><b>operator&lt;&lt;</b></a> ( Q_LONG&nbsp;i )</li>
80<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-a"><b>operator&lt;&lt;</b></a> ( Q_ULONG&nbsp;i )</li>
81<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-b"><b>operator&lt;&lt;</b></a> ( float&nbsp;f )</li>
82<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-c"><b>operator&lt;&lt;</b></a> ( double&nbsp;f )</li>
83<li class=fn>QDataStream &amp; <a href="#operator-lt-lt-d"><b>operator&lt;&lt;</b></a> ( const&nbsp;char&nbsp;*&nbsp;s )</li>
84<li class=fn>QDataStream &amp; <a href="#readBytes"><b>readBytes</b></a> ( char&nbsp;*&amp;&nbsp;s, uint&nbsp;&amp;&nbsp;l )</li>
85<li class=fn>QDataStream &amp; <a href="#readRawBytes"><b>readRawBytes</b></a> ( char&nbsp;*&nbsp;s, uint&nbsp;len )</li>
86<li class=fn>QDataStream &amp; <a href="#writeBytes"><b>writeBytes</b></a> ( const&nbsp;char&nbsp;*&nbsp;s, uint&nbsp;len )</li>
87<li class=fn>QDataStream &amp; <a href="#writeRawBytes"><b>writeRawBytes</b></a> ( const&nbsp;char&nbsp;*&nbsp;s, uint&nbsp;len )</li>
88</ul>
89<hr><a name="details"></a><h2>Detailed Description</h2>
90
91
92
93The QDataStream class provides serialization of binary data
94to a <a href="qiodevice.html">QIODevice</a>.
95<p>
96<p> A data stream is a binary stream of encoded information which is
97100% independent of the host computer's operating system, CPU or
98byte order. For example, a data stream that is written by a PC
99under Windows can be read by a Sun SPARC running Solaris.
100<p> You can also use a data stream to read/write <a href="#raw">raw
101 unencoded binary data</a>. If you want a "parsing" input
102stream, see <a href="qtextstream.html">QTextStream</a>.
103<p> The QDataStream class implements the serialization of C++'s basic
104data types, like <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>char*</tt>, etc.
105Serialization of more complex data is accomplished by breaking up
106the data into primitive units.
107<p> A data stream cooperates closely with a QIODevice. A QIODevice
108represents an input/output medium one can read data from and write
109data to. The <a href="qfile.html">QFile</a> class is an example of an IO device.
110<p> Example (write binary data to a stream):
111<pre>
112 <a href="qfile.html">QFile</a> file( "file.dat" );
113 file.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_WriteOnly</a> );
114 QDataStream stream( &amp;file ); // we will serialize the data into the file
115 stream &lt;&lt; "the answer is"; // serialize a string
116 stream &lt;&lt; (Q_INT32)42; // serialize an integer
117 </pre>
118
119<p> Example (read binary data from a stream):
120<pre>
121 <a href="qfile.html">QFile</a> file( "file.dat" );
122 file.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadOnly</a> );
123 QDataStream stream( &amp;file ); // read the data serialized from the file
124 <a href="qstring.html">QString</a> str;
125 Q_INT32 a;
126 stream &gt;&gt; str &gt;&gt; a; // extract "the answer is" and 42
127 </pre>
128
129<p> Each item written to the stream is written in a predefined binary
130format that varies depending on the item's type. Supported Qt
131types include <a href="qbrush.html">QBrush</a>, <a href="qcolor.html">QColor</a>, <a href="qdatetime.html">QDateTime</a>, <a href="qfont.html">QFont</a>, <a href="qpixmap.html">QPixmap</a>, <a href="qstring.html">QString</a>,
132<a href="qvariant.html">QVariant</a> and many others. For the complete list of all Qt types
133supporting data streaming see the <a href="datastreamformat.html">Format of the QDataStream operators</a>.
134<p> For integers it is best to always cast to a Qt integer type for
135writing, and to read back into the same Qt integer type. This
136ensures that you get integers of the size you want and insulates
137you from compiler and platform differences.
138<p> To take one example, a <tt>char*</tt> string is written as a 32-bit
139integer equal to the length of the string including the NUL byte
140('&#92;0'), followed by all the characters of the string including the
141NUL byte. When reading a <tt>char*</tt> string, 4 bytes are read to
142create the 32-bit length value, then that many characters for the
143<tt>char*</tt> string including the NUL are read.
144<p> The initial IODevice is usually set in the constructor, but can be
145changed with <a href="#setDevice">setDevice</a>(). If you've reached the end of the data
146(or if there is no IODevice set) <a href="#atEnd">atEnd</a>() will return TRUE.
147<p> If you want the data to be compatible with an earlier version of
148Qt use <a href="#setVersion">setVersion</a>().
149<p> If you want the data to be human-readable, e.g. for debugging, you
150can set the data stream into printable data mode with
151<a href="#setPrintableData">setPrintableData</a>(). The data is then written slower, in a bloated
152but human readable format.
153<p> If you are producing a new binary data format, such as a file
154format for documents created by your application, you could use a
155QDataStream to write the data in a portable format. Typically, you
156would write a brief header containing a magic string and a version
157number to give yourself room for future expansion. For example:
158<p> <pre>
159 <a href="qfile.html">QFile</a> file( "file.xxx" );
160 file.<a href="qfile.html#open">open</a>( IO_WriteOnly );
161 QDataStream stream( &amp;file );
162
163 // Write a header with a "magic number" and a version
164 stream &lt;&lt; (Q_UINT32)0xA0B0C0D0;
165 stream &lt;&lt; (Q_INT32)123;
166
167 // Write the data
168 stream &lt;&lt; [lots of interesting data]
169 </pre>
170
171<p> Then read it in with:
172<p> <pre>
173 <a href="qfile.html">QFile</a> file( "file.xxx" );
174 file.<a href="qfile.html#open">open</a>( IO_ReadOnly );
175 QDataStream stream( &amp;file );
176
177 // Read and check the header
178 Q_UINT32 magic;
179 stream &gt;&gt; magic;
180 if ( magic != 0xA0B0C0D0 )
181 return XXX_BAD_FILE_FORMAT;
182
183 // Read the version
184 Q_INT32 version;
185 stream &gt;&gt; version;
186 if ( version &lt; 100 )
187 return XXX_BAD_FILE_TOO_OLD;
188 if ( version &gt; 123 )
189 return XXX_BAD_FILE_TOO_NEW;
190 if ( version &lt;= 110 )
191 stream.<a href="#setVersion">setVersion</a>(1);
192
193 // Read the data
194 stream &gt;&gt; [lots of interesting data];
195 if ( version &gt; 120 )
196 stream &gt;&gt; [data new in XXX version 1.2];
197 stream &gt;&gt; [other interesting data];
198 </pre>
199
200<p> You can select which byte order to use when serializing data. The
201default setting is big endian (MSB first). Changing it to little
202endian breaks the portability (unless the reader also changes to
203little endian). We recommend keeping this setting unless you have
204special requirements.
205<p> <a name="raw"></a>
206<h3> Reading and writing raw binary data
207</h3>
208<a name="1"></a><p> You may wish to read/write your own raw binary data to/from the
209data stream directly. Data may be read from the stream into a
210preallocated char* using <a href="#readRawBytes">readRawBytes</a>(). Similarly data can be
211written to the stream using <a href="#writeRawBytes">writeRawBytes</a>(). Notice that any
212encoding/decoding of the data must be done by you.
213<p> A similar pair of functions is <a href="#readBytes">readBytes</a>() and <a href="#writeBytes">writeBytes</a>(). These
214differ from their <em>raw</em> counterparts as follows: readBytes()
215reads a Q_UINT32 which is taken to be the length of the data to be
216read, then that number of bytes is read into the preallocated
217char*; writeBytes() writes a Q_UINT32 containing the length of the
218data, followed by the data. Notice that any encoding/decoding of
219the data (apart from the length Q_UINT32) must be done by you.
220<p> <p>See also <a href="qtextstream.html">QTextStream</a>, <a href="qvariant.html">QVariant</a>, and <a href="io.html">Input/Output and Networking</a>.
221
222<hr><h2>Member Type Documentation</h2>
223<h3 class=fn><a name="ByteOrder-enum"></a>QDataStream::ByteOrder</h3>
224
225<p> The byte order used for reading/writing the data.
226<ul>
227<li><tt>QDataStream::BigEndian</tt> - the default
228<li><tt>QDataStream::LittleEndian</tt>
229</ul>
230<hr><h2>Member Function Documentation</h2>
231<h3 class=fn><a name="QDataStream"></a>QDataStream::QDataStream ()
232</h3>
233Constructs a data stream that has no IO device.
234<p> <p>See also <a href="#setDevice">setDevice</a>().
235
236<h3 class=fn><a name="QDataStream-2"></a>QDataStream::QDataStream ( <a href="qiodevice.html">QIODevice</a>&nbsp;*&nbsp;d )
237</h3>
238Constructs a data stream that uses the IO device <em>d</em>.
239<p> <b>Warning:</b> If you use <a href="qsocket.html">QSocket</a> or <a href="qsocketdevice.html">QSocketDevice</a> as the IO device <em>d</em>
240for reading data, you must make sure that enough data is available
241on the socket for the operation to successfully proceed;
242QDataStream does not have any means to handle or recover from
243short-reads.
244<p> <p>See also <a href="#setDevice">setDevice</a>() and <a href="#device">device</a>().
245
246<h3 class=fn><a name="QDataStream-3"></a>QDataStream::QDataStream ( <a href="qbytearray.html">QByteArray</a>&nbsp;a, int&nbsp;mode )
247</h3>
248Constructs a data stream that operates on a byte array, <em>a</em>,
249through an internal <a href="qbuffer.html">QBuffer</a> device. The <em>mode</em> is a
250<a href="qiodevice.html#mode">QIODevice::mode</a>(), usually either <a href="qfile.html#open">IO_ReadOnly</a> or <a href="qfile.html#open">IO_WriteOnly</a>.
251<p> Example:
252<pre>
253 static char bindata[] = { 231, 1, 44, ... };
254 <a href="qbytearray.html">QByteArray</a> a;
255 a.<a href="qmemarray.html#setRawData">setRawData</a>( bindata, sizeof(bindata) ); // a points to bindata
256 QDataStream stream( a, <a href="qfile.html#open">IO_ReadOnly</a> ); // open on a's data
257 stream &gt;&gt; [something]; // read raw bindata
258 a.<a href="qmemarray.html#resetRawData">resetRawData</a>( bindata, sizeof(bindata) ); // finished
259 </pre>
260
261<p> The <a href="qmemarray.html#setRawData">QByteArray::setRawData</a>() function is not for the inexperienced.
262
263<h3 class=fn><a name="~QDataStream"></a>QDataStream::~QDataStream ()<tt> [virtual]</tt>
264</h3>
265Destroys the data stream.
266<p> The destructor will not affect the current IO device, unless it is
267an internal IO device processing a <a href="qbytearray.html">QByteArray</a> passed in the <em>constructor</em>, in which case the internal IO device is destroyed.
268
269<h3 class=fn>bool <a name="atEnd"></a>QDataStream::atEnd () const
270</h3>
271
272<p> Returns TRUE if the IO device has reached the end position (end of
273the stream or file) or if there is no IO device set; otherwise
274returns FALSE, i.e. if the current position of the IO device is
275before the end position.
276<p> <p>See also <a href="qiodevice.html#atEnd">QIODevice::atEnd</a>().
277
278<h3 class=fn>int <a name="byteOrder"></a>QDataStream::byteOrder () const
279</h3>
280
281<p> Returns the current byte order setting -- either <a href="#ByteOrder-enum">BigEndian</a> or
282<a href="#ByteOrder-enum">LittleEndian</a>.
283<p> <p>See also <a href="#setByteOrder">setByteOrder</a>().
284
285<h3 class=fn><a href="qiodevice.html">QIODevice</a>&nbsp;* <a name="device"></a>QDataStream::device () const
286</h3>
287
288<p> Returns the IO device currently set.
289<p> <p>See also <a href="#setDevice">setDevice</a>() and <a href="#unsetDevice">unsetDevice</a>().
290
291<h3 class=fn>bool <a name="eof"></a>QDataStream::eof () const
292</h3>
293<p> <b>This function is obsolete.</b> It is provided to keep old source working. We strongly advise against using it in new code.
294<p> Returns TRUE if the IO device has reached the end position (end of
295stream or file) or if there is no IO device set.
296<p> Returns FALSE if the current position of the read/write head of the IO
297device is somewhere before the end position.
298<p> <p>See also <a href="qiodevice.html#atEnd">QIODevice::atEnd</a>().
299
300<h3 class=fn>bool <a name="isPrintableData"></a>QDataStream::isPrintableData () const
301</h3>
302
303<p> Returns TRUE if the printable data flag has been set; otherwise
304returns FALSE.
305<p> <p>See also <a href="#setPrintableData">setPrintableData</a>().
306
307<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt"></a>QDataStream::operator&lt;&lt; ( Q_INT8&nbsp;i )
308</h3>
309Writes a signed byte, <em>i</em>, to the stream and returns a reference
310to the stream.
311
312<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-2"></a>QDataStream::operator&lt;&lt; ( Q_UINT8&nbsp;i )
313</h3>
314This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
315<p> Writes an unsigned byte, <em>i</em>, to the stream and returns a
316reference to the stream.
317
318<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-3"></a>QDataStream::operator&lt;&lt; ( Q_INT16&nbsp;i )
319</h3>
320This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
321<p> Writes a signed 16-bit integer, <em>i</em>, to the stream and returns a
322reference to the stream.
323
324<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-4"></a>QDataStream::operator&lt;&lt; ( Q_UINT16&nbsp;i )
325</h3>
326This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
327<p> Writes an unsigned 16-bit integer, <em>i</em>, to the stream and returns
328a reference to the stream.
329
330<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-5"></a>QDataStream::operator&lt;&lt; ( Q_INT32&nbsp;i )
331</h3>
332This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
333<p> Writes a signed 32-bit integer, <em>i</em>, to the stream and returns a
334reference to the stream.
335
336<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-6"></a>QDataStream::operator&lt;&lt; ( Q_UINT32&nbsp;i )
337</h3>
338This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
339<p> Writes an unsigned integer, <em>i</em>, to the stream as a 32-bit
340unsigned integer (Q_UINT32). Returns a reference to the stream.
341
342<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-7"></a>QDataStream::operator&lt;&lt; ( Q_INT64&nbsp;i )
343</h3>
344This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
345<p> Writes a signed 64-bit integer, <em>i</em>, to the stream and returns a
346reference to the stream.
347
348<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-8"></a>QDataStream::operator&lt;&lt; ( Q_UINT64&nbsp;i )
349</h3>
350This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
351<p> Writes an unsigned 64-bit integer, <em>i</em>, to the stream and returns a
352reference to the stream.
353
354<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-9"></a>QDataStream::operator&lt;&lt; ( Q_LONG&nbsp;i )
355</h3>
356This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
357<p> Writes a signed integer <em>i</em>, of the system's word length, to the
358stream and returns a reference to the stream.
359
360<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-a"></a>QDataStream::operator&lt;&lt; ( Q_ULONG&nbsp;i )
361</h3>
362This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
363<p> Writes an unsigned integer <em>i</em>, of the system's word length, to
364the stream and returns a reference to the stream.
365
366<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-b"></a>QDataStream::operator&lt;&lt; ( float&nbsp;f )
367</h3>
368This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
369<p> Writes a 32-bit floating point number, <em>f</em>, to the stream using
370the standard IEEE754 format. Returns a reference to the stream.
371
372<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-c"></a>QDataStream::operator&lt;&lt; ( double&nbsp;f )
373</h3>
374This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
375<p> Writes a 64-bit floating point number, <em>f</em>, to the stream using
376the standard IEEE754 format. Returns a reference to the stream.
377
378<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-lt-lt-d"></a>QDataStream::operator&lt;&lt; ( const&nbsp;char&nbsp;*&nbsp;s )
379</h3>
380This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
381<p> Writes the '&#92;0'-terminated string <em>s</em> to the stream and returns a
382reference to the stream.
383<p> The string is serialized using <a href="#writeBytes">writeBytes</a>().
384
385<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt"></a>QDataStream::operator&gt;&gt; ( Q_INT8&nbsp;&amp;&nbsp;i )
386</h3>
387Reads a signed byte from the stream into <em>i</em>, and returns a
388reference to the stream.
389
390<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-2"></a>QDataStream::operator&gt;&gt; ( Q_UINT8&nbsp;&amp;&nbsp;i )
391</h3>
392This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
393<p> Reads an unsigned byte from the stream into <em>i</em>, and returns a
394reference to the stream.
395
396<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-3"></a>QDataStream::operator&gt;&gt; ( Q_INT16&nbsp;&amp;&nbsp;i )
397</h3>
398This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
399<p> Reads a signed 16-bit integer from the stream into <em>i</em>, and
400returns a reference to the stream.
401
402<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-4"></a>QDataStream::operator&gt;&gt; ( Q_UINT16&nbsp;&amp;&nbsp;i )
403</h3>
404This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
405<p> Reads an unsigned 16-bit integer from the stream into <em>i</em>, and
406returns a reference to the stream.
407
408<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-5"></a>QDataStream::operator&gt;&gt; ( Q_INT32&nbsp;&amp;&nbsp;i )
409</h3>
410This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
411<p> Reads a signed 32-bit integer from the stream into <em>i</em>, and
412returns a reference to the stream.
413
414<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-6"></a>QDataStream::operator&gt;&gt; ( Q_UINT32&nbsp;&amp;&nbsp;i )
415</h3>
416This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
417<p> Reads an unsigned 32-bit integer from the stream into <em>i</em>, and
418returns a reference to the stream.
419
420<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-7"></a>QDataStream::operator&gt;&gt; ( Q_INT64&nbsp;&amp;&nbsp;i )
421</h3>
422This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
423<p> Reads a signed 64-bit integer from the stream into <em>i</em>, and
424returns a reference to the stream.
425
426<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-8"></a>QDataStream::operator&gt;&gt; ( Q_UINT64&nbsp;&amp;&nbsp;i )
427</h3>
428This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
429<p> Reads an unsigned 64-bit integer from the stream, into <em>i</em>, and
430returns a reference to the stream.
431
432<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-9"></a>QDataStream::operator&gt;&gt; ( Q_LONG&nbsp;&amp;&nbsp;i )
433</h3>
434This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
435<p> Reads a signed integer of the system's word length from the stream
436into <em>i</em>, and returns a reference to the stream.
437<p>
438<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-a"></a>QDataStream::operator&gt;&gt; ( Q_ULONG&nbsp;&amp;&nbsp;i )
439</h3>
440This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
441<p> Reads an unsigned integer of the system's word length from the
442stream, into <em>i</em>, and returns a reference to the stream.
443
444<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-b"></a>QDataStream::operator&gt;&gt; ( float&nbsp;&amp;&nbsp;f )
445</h3>
446This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
447<p> Reads a 32-bit floating point number from the stream into <em>f</em>,
448using the standard IEEE754 format. Returns a reference to the
449stream.
450
451<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-c"></a>QDataStream::operator&gt;&gt; ( double&nbsp;&amp;&nbsp;f )
452</h3>
453This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
454<p> Reads a 64-bit floating point number from the stream into <em>f</em>,
455using the standard IEEE754 format. Returns a reference to the
456stream.
457
458<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="operator-gt-gt-d"></a>QDataStream::operator&gt;&gt; ( char&nbsp;*&amp;&nbsp;s )
459</h3>
460This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
461<p> Reads the '&#92;0'-terminated string <em>s</em> from the stream and returns
462a reference to the stream.
463<p> Space for the string is allocated using <tt>new</tt> -- the caller must
464destroy it with delete[].
465
466<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="readBytes"></a>QDataStream::readBytes ( char&nbsp;*&amp;&nbsp;s, uint&nbsp;&amp;&nbsp;l )
467</h3>
468Reads the buffer <em>s</em> from the stream and returns a reference to
469the stream.
470<p> The buffer <em>s</em> is allocated using <tt>new</tt>. Destroy it with the <tt>delete[]</tt> operator. If the length is zero or <em>s</em> cannot be
471allocated, <em>s</em> is set to 0.
472<p> The <em>l</em> parameter will be set to the length of the buffer.
473<p> The serialization format is a Q_UINT32 length specifier first,
474then <em>l</em> bytes of data. Note that the data is <em>not</em> encoded.
475<p> <p>See also <a href="#readRawBytes">readRawBytes</a>() and <a href="#writeBytes">writeBytes</a>().
476
477<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="readRawBytes"></a>QDataStream::readRawBytes ( char&nbsp;*&nbsp;s, uint&nbsp;len )
478</h3>
479Reads <em>len</em> bytes from the stream into <em>s</em> and returns a
480reference to the stream.
481<p> The buffer <em>s</em> must be preallocated. The data is <em>not</em> encoded.
482<p> <p>See also <a href="#readBytes">readBytes</a>(), <a href="qiodevice.html#readBlock">QIODevice::readBlock</a>(), and <a href="#writeRawBytes">writeRawBytes</a>().
483
484<h3 class=fn>void <a name="setByteOrder"></a>QDataStream::setByteOrder ( int&nbsp;bo )
485</h3>
486Sets the serialization byte order to <em>bo</em>.
487<p> The <em>bo</em> parameter can be <a href="#ByteOrder-enum">QDataStream::BigEndian</a> or <a href="#ByteOrder-enum">QDataStream::LittleEndian</a>.
488<p> The default setting is big endian. We recommend leaving this
489setting unless you have special requirements.
490<p> <p>See also <a href="#byteOrder">byteOrder</a>().
491
492<h3 class=fn>void <a name="setDevice"></a>QDataStream::setDevice ( <a href="qiodevice.html">QIODevice</a>&nbsp;*&nbsp;d )
493</h3>
494void <a href="#setDevice">QDataStream::setDevice</a>(<a href="qiodevice.html">QIODevice</a> *d )
495<p> Sets the IO device to <em>d</em>.
496<p> <p>See also <a href="#device">device</a>() and <a href="#unsetDevice">unsetDevice</a>().
497
498<h3 class=fn>void <a name="setPrintableData"></a>QDataStream::setPrintableData ( bool&nbsp;enable )
499</h3>
500
501<p> If <em>enable</em> is TRUE, data will be output in a human readable
502format. If <em>enable</em> is FALSE, data will be output in a binary
503format.
504<p> If <em>enable</em> is TRUE, the write functions will generate output
505that consists of printable characters (7 bit ASCII). This output
506will typically be a lot larger than the default binary output, and
507consequently slower to write.
508<p> We recommend only enabling printable data for debugging purposes.
509
510<h3 class=fn>void <a name="setVersion"></a>QDataStream::setVersion ( int&nbsp;v )
511</h3>
512
513<p> Sets the version number of the data serialization format to <em>v</em>.
514<p> You don't need to set a version if you are using the current
515version of Qt.
516<p> In order to accommodate new functionality, the datastream
517serialization format of some Qt classes has changed in some
518versions of Qt. If you want to read data that was created by an
519earlier version of Qt, or write data that can be read by a program
520that was compiled with an earlier version of Qt, use this function
521to modify the serialization format of QDataStream.
522<p> <center><table cellpadding="4" cellspacing="2" border="0">
523<tr bgcolor="#a2c511"> <th valign="top">Qt Version <th valign="top">QDataStream Version
524<tr bgcolor="#f0f0f0"> <td valign="top">Qt 3.3 <td valign="top" colspan="1" rowspan="1"> 6
525<tr bgcolor="#d0d0d0"> <td valign="top">Qt 3.2 <td valign="top" colspan="1" rowspan="1"> 5
526<tr bgcolor="#f0f0f0"> <td valign="top">Qt 3.1 <td valign="top" colspan="1" rowspan="1"> 5
527<tr bgcolor="#d0d0d0"> <td valign="top">Qt 3.0 <td valign="top" colspan="1" rowspan="1"> 4
528<tr bgcolor="#f0f0f0"> <td valign="top">Qt 2.1.x and Qt 2.2.x <td valign="top" colspan="1" rowspan="1"> 3
529<tr bgcolor="#d0d0d0"> <td valign="top">Qt 2.0.x <td valign="top" colspan="1" rowspan="1"> 2
530<tr bgcolor="#f0f0f0"> <td valign="top">Qt 1.x <td valign="top" colspan="1" rowspan="1"> 1
531</table></center>
532<p> <p>See also <a href="#version">version</a>().
533
534<h3 class=fn>void <a name="unsetDevice"></a>QDataStream::unsetDevice ()
535</h3>
536Unsets the IO device. This is the same as calling <a href="#setDevice">setDevice</a>( 0 ).
537<p> <p>See also <a href="#device">device</a>() and <a href="#setDevice">setDevice</a>().
538
539<h3 class=fn>int <a name="version"></a>QDataStream::version () const
540</h3>
541
542<p> Returns the version number of the data serialization format. In Qt
5433.1, this number is 5.
544<p> <p>See also <a href="#setVersion">setVersion</a>().
545
546<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="writeBytes"></a>QDataStream::writeBytes ( const&nbsp;char&nbsp;*&nbsp;s, uint&nbsp;len )
547</h3>
548Writes the length specifier <em>len</em> and the buffer <em>s</em> to the
549stream and returns a reference to the stream.
550<p> The <em>len</em> is serialized as a Q_UINT32, followed by <em>len</em> bytes
551from <em>s</em>. Note that the data is <em>not</em> encoded.
552<p> <p>See also <a href="#writeRawBytes">writeRawBytes</a>() and <a href="#readBytes">readBytes</a>().
553
554<h3 class=fn><a href="qdatastream.html">QDataStream</a>&nbsp;&amp; <a name="writeRawBytes"></a>QDataStream::writeRawBytes ( const&nbsp;char&nbsp;*&nbsp;s, uint&nbsp;len )
555</h3>
556Writes <em>len</em> bytes from <em>s</em> to the stream and returns a
557reference to the stream. The data is <em>not</em> encoded.
558<p> <p>See also <a href="#writeBytes">writeBytes</a>(), <a href="qiodevice.html#writeBlock">QIODevice::writeBlock</a>(), and <a href="#readRawBytes">readRawBytes</a>().
559
560<!-- eof -->
561<hr><p>
562This file is part of the <a href="index.html">Qt toolkit</a>.
563Copyright &copy; 1995-2007
564<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
565<table width=100% cellspacing=0 border=0><tr>
566<td>Copyright &copy; 2007
567<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
568<td align=right><div align=right>Qt 3.3.8</div>
569</table></div></address></body>
570</html>
Note: See TracBrowser for help on using the repository browser.