File: qdatastream.html

package info (click to toggle)
qt4-x11 4%3A4.8.2%2Bdfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 701,696 kB
  • sloc: cpp: 2,686,179; ansic: 375,485; python: 25,859; sh: 19,349; xml: 17,091; perl: 14,765; yacc: 5,383; asm: 5,038; makefile: 1,259; lex: 555; ruby: 526; objc: 347; cs: 112; pascal: 112; php: 54; sed: 34
file content (549 lines) | stat: -rw-r--r-- 60,531 bytes parent folder | download
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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en_US" lang="en_US">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qdatastream.cpp -->
  <title>Qt 4.8: QDataStream Class Reference</title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="content"> 
    <a href="index.html" class="qtref"><span>Qt Reference Documentation</span></a>
  </div>
  <div class="breadcrumb toolblock">
    <ul>
      <li class="first"><a href="index.html">Home</a></li>
      <!--  Breadcrumbs go here -->
<li><a href="modules.html">Modules</a></li>
<li><a href="qtcore.html">QtCore</a></li>
<li>QDataStream</li>
    </ul>
  </div>
</div>
<div class="content mainContent">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-types">Public Types</a></li>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
<li class="level2"><a href="#versioning">Versioning</a></li>
<li class="level2"><a href="#reading-and-writing-raw-binary-data">Reading and writing raw binary data</a></li>
<li class="level2"><a href="#reading-and-writing-qt-collection-classes">Reading and writing Qt collection classes</a></li>
<li class="level2"><a href="#reading-and-writing-other-qt-classes">Reading and writing other Qt classes.</a></li>
</ul>
</div>
<h1 class="title">QDataStream Class Reference</h1>
<!-- $$$QDataStream-brief -->
<p>The QDataStream class provides serialization of binary data to a <a href="qiodevice.html">QIODevice</a>. <a href="#details">More...</a></p>
<!-- @@@QDataStream -->
<pre class="cpp"> <span class="preprocessor">#include &lt;QDataStream&gt;</span></pre><p><b>Note:</b> All functions in this class are <a href="threads-reentrancy.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qdatastream-members.html">List of all members, including inherited members</a></li>
<li><a href="qdatastream-obsolete.html">Obsolete members</a></li>
<li><a href="qdatastream-qt3.html">Qt 3 support members</a></li>
</ul>
<a name="public-types"></a>
<h2>Public Types</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#ByteOrder-enum">ByteOrder</a></b> { BigEndian, LittleEndian }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#FloatingPointPrecision-enum">FloatingPointPrecision</a></b> { SinglePrecision, DoublePrecision }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#Status-enum">Status</a></b> { Ok, ReadPastEnd, ReadCorruptData, WriteFailed }</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> enum </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#Version-enum">Version</a></b> { Qt_1_0, Qt_2_0, Qt_2_1, Qt_3_0, ..., Qt_4_8 }</td></tr>
</table>
<a name="public-functions"></a>
<h2>Public Functions</h2>
<table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#QDataStream">QDataStream</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#QDataStream-2">QDataStream</a></b> ( QIODevice * <i>d</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#QDataStream-4">QDataStream</a></b> ( QByteArray * <i>a</i>, QIODevice::OpenMode <i>mode</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#QDataStream-5">QDataStream</a></b> ( const QByteArray &amp; <i>a</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#dtor.QDataStream">~QDataStream</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> bool </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#atEnd">atEnd</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> ByteOrder </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#byteOrder">byteOrder</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QIODevice * </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#device">device</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> FloatingPointPrecision </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#floatingPointPrecision">floatingPointPrecision</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#readBytes">readBytes</a></b> ( char *&amp; <i>s</i>, uint &amp; <i>l</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#readRawData">readRawData</a></b> ( char * <i>s</i>, int <i>len</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#resetStatus">resetStatus</a></b> ()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#setByteOrder">setByteOrder</a></b> ( ByteOrder <i>bo</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#setDevice">setDevice</a></b> ( QIODevice * <i>d</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a></b> ( FloatingPointPrecision <i>precision</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#setStatus">setStatus</a></b> ( Status <i>status</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#setVersion">setVersion</a></b> ( int <i>v</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#skipRawData">skipRawData</a></b> ( int <i>len</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> Status </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#status">status</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#version">version</a></b> () const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#writeBytes">writeBytes</a></b> ( const char * <i>s</i>, uint <i>len</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> int </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#writeRawData">writeRawData</a></b> ( const char * <i>s</i>, int <i>len</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt">operator&lt;&lt;</a></b> ( qint8 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-2">operator&lt;&lt;</a></b> ( bool <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-3">operator&lt;&lt;</a></b> ( quint8 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-4">operator&lt;&lt;</a></b> ( quint16 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-5">operator&lt;&lt;</a></b> ( qint16 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-6">operator&lt;&lt;</a></b> ( qint32 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-7">operator&lt;&lt;</a></b> ( quint64 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-8">operator&lt;&lt;</a></b> ( qint64 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-9">operator&lt;&lt;</a></b> ( quint32 <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-10">operator&lt;&lt;</a></b> ( float <i>f</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-11">operator&lt;&lt;</a></b> ( double <i>f</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-lt-lt-12">operator&lt;&lt;</a></b> ( const char * <i>s</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt">operator&gt;&gt;</a></b> ( qint8 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-2">operator&gt;&gt;</a></b> ( bool &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-3">operator&gt;&gt;</a></b> ( quint8 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-4">operator&gt;&gt;</a></b> ( quint16 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-5">operator&gt;&gt;</a></b> ( qint16 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-6">operator&gt;&gt;</a></b> ( quint32 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-7">operator&gt;&gt;</a></b> ( qint32 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-8">operator&gt;&gt;</a></b> ( quint64 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-9">operator&gt;&gt;</a></b> ( qint64 &amp; <i>i</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-10">operator&gt;&gt;</a></b> ( float &amp; <i>f</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-11">operator&gt;&gt;</a></b> ( double &amp; <i>f</i> )</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QDataStream &amp; </td><td class="memItemRight bottomAlign"><b><a href="qdatastream.html#operator-gt-gt-12">operator&gt;&gt;</a></b> ( char *&amp; <i>s</i> )</td></tr>
</table>
<a name="details"></a>
<!-- $$$QDataStream-description -->
<div class="descr">
<h2>Detailed Description</h2>
<p>The QDataStream class provides serialization of binary data to a <a href="qiodevice.html">QIODevice</a>.</p>
<p>A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order. For example, a data stream that is written by a PC under Windows can be read by a Sun SPARC running Solaris.</p>
<p>You can also use a data stream to read/write <a href="#raw">raw unencoded binary data</a>. If you want a &quot;parsing&quot; input stream, see <a href="qtextstream.html">QTextStream</a>.</p>
<p>The QDataStream class implements the serialization of C++'s basic data types, like <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>char *</tt>, etc. Serialization of more complex data is accomplished by breaking up the data into primitive units.</p>
<p>A data stream cooperates closely with a <a href="qiodevice.html">QIODevice</a>. A <a href="qiodevice.html">QIODevice</a> represents an input/output medium one can read data from and write data to. The <a href="qfile.html">QFile</a> class is an example of an I/O device.</p>
<p>Example (write binary data to a stream):</p>
<pre class="cpp"> <span class="type"><a href="qfile.html">QFile</a></span> file(<span class="string">&quot;file.dat&quot;</span>);
 file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">::</span>WriteOnly);
 <span class="type">QDataStream</span> out(<span class="operator">&amp;</span>file);   <span class="comment">// we will serialize the data into the file</span>
 out <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="qstring.html">QString</a></span>(<span class="string">&quot;the answer is&quot;</span>);   <span class="comment">// serialize a string</span>
 out <span class="operator">&lt;</span><span class="operator">&lt;</span> (<span class="type"><a href="qtglobal.html#qint32-typedef">qint32</a></span>)<span class="number">42</span>;        <span class="comment">// serialize an integer</span></pre>
<p>Example (read binary data from a stream):</p>
<pre class="cpp"> <span class="type"><a href="qfile.html">QFile</a></span> file(<span class="string">&quot;file.dat&quot;</span>);
 file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">::</span>ReadOnly);
 <span class="type">QDataStream</span> in(<span class="operator">&amp;</span>file);    <span class="comment">// read the data serialized from the file</span>
 <span class="type"><a href="qstring.html">QString</a></span> str;
 <span class="type"><a href="qtglobal.html#qint32-typedef">qint32</a></span> a;
 in <span class="operator">&gt;</span><span class="operator">&gt;</span> str <span class="operator">&gt;</span><span class="operator">&gt;</span> a;           <span class="comment">// extract &quot;the answer is&quot; and 42</span></pre>
<p>Each item written to the stream is written in a predefined binary format that varies depending on the item's type. Supported Qt types 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>, <a href="qvariant.html">QVariant</a> and many others. For the complete list of all Qt types supporting data streaming see <a href="datastreamformat.html">Serializing Qt Data Types</a>.</p>
<p>For integers it is best to always cast to a Qt integer type for writing, and to read back into the same Qt integer type. This ensures that you get integers of the size you want and insulates you from compiler and platform differences.</p>
<p>To take one example, a <tt>char *</tt> string is written as a 32-bit integer equal to the length of the string including the '\0' byte, followed by all the characters of the string including the '\0' byte. When reading a <tt>char *</tt> string, 4 bytes are read to create the 32-bit length value, then that many characters for the <tt>char *</tt> string including the '\0' terminator are read.</p>
<p>The initial I/O device is usually set in the constructor, but can be changed with <a href="qdatastream.html#setDevice">setDevice</a>(). If you've reached the end of the data (or if there is no I/O device set) <a href="qdatastream.html#atEnd">atEnd</a>() will return true.</p>
<a name="versioning"></a>
<h3>Versioning</h3>
<p>QDataStream's binary format has evolved since Qt 1.0, and is likely to continue evolving to reflect changes done in Qt. When inputting or outputting complex types, it's very important to make sure that the same version of the stream (<a href="qdatastream.html#version">version</a>()) is used for reading and writing. If you need both forward and backward compatibility, you can hardcode the version number in the application:</p>
<pre class="cpp"> stream<span class="operator">.</span>setVersion(<span class="type">QDataStream</span><span class="operator">::</span>Qt_4_0);</pre>
<p>If you are producing a new binary data format, such as a file format for documents created by your application, you could use a QDataStream to write the data in a portable format. Typically, you would write a brief header containing a magic string and a version number to give yourself room for future expansion. For example:</p>
<pre class="cpp"> <span class="type"><a href="qfile.html">QFile</a></span> file(<span class="string">&quot;file.xxx&quot;</span>);
 file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">::</span>WriteOnly);
 <span class="type">QDataStream</span> out(<span class="operator">&amp;</span>file);

 <span class="comment">// Write a header with a &quot;magic number&quot; and a version</span>
 out <span class="operator">&lt;</span><span class="operator">&lt;</span> (<span class="type"><a href="qtglobal.html#quint32-typedef">quint32</a></span>)<span class="number">0xA0B0C0D0</span>;
 out <span class="operator">&lt;</span><span class="operator">&lt;</span> (<span class="type"><a href="qtglobal.html#qint32-typedef">qint32</a></span>)<span class="number">123</span>;

 out<span class="operator">.</span>setVersion(<span class="type">QDataStream</span><span class="operator">::</span>Qt_4_0);

 <span class="comment">// Write the data</span>
 out <span class="operator">&lt;</span><span class="operator">&lt;</span> lots_of_interesting_data;</pre>
<p>Then read it in with:</p>
<pre class="cpp"> <span class="type"><a href="qfile.html">QFile</a></span> file(<span class="string">&quot;file.xxx&quot;</span>);
 file<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">::</span>ReadOnly);
 <span class="type">QDataStream</span> in(<span class="operator">&amp;</span>file);

 <span class="comment">// Read and check the header</span>
 <span class="type"><a href="qtglobal.html#quint32-typedef">quint32</a></span> magic;
 in <span class="operator">&gt;</span><span class="operator">&gt;</span> magic;
 <span class="keyword">if</span> (magic <span class="operator">!</span><span class="operator">=</span> <span class="number">0xA0B0C0D0</span>)
     <span class="keyword">return</span> XXX_BAD_FILE_FORMAT;

 <span class="comment">// Read the version</span>
 <span class="type"><a href="qtglobal.html#qint32-typedef">qint32</a></span> version;
 in <span class="operator">&gt;</span><span class="operator">&gt;</span> version;
 <span class="keyword">if</span> (version <span class="operator">&lt;</span> <span class="number">100</span>)
     <span class="keyword">return</span> XXX_BAD_FILE_TOO_OLD;
 <span class="keyword">if</span> (version <span class="operator">&gt;</span> <span class="number">123</span>)
     <span class="keyword">return</span> XXX_BAD_FILE_TOO_NEW;

 <span class="keyword">if</span> (version <span class="operator">&lt;</span><span class="operator">=</span> <span class="number">110</span>)
     in<span class="operator">.</span>setVersion(<span class="type">QDataStream</span><span class="operator">::</span>Qt_3_2);
 <span class="keyword">else</span>
     in<span class="operator">.</span>setVersion(<span class="type">QDataStream</span><span class="operator">::</span>Qt_4_0);

 <span class="comment">// Read the data</span>
 in <span class="operator">&gt;</span><span class="operator">&gt;</span> lots_of_interesting_data;
 <span class="keyword">if</span> (version <span class="operator">&gt;</span><span class="operator">=</span> <span class="number">120</span>)
     in <span class="operator">&gt;</span><span class="operator">&gt;</span> data_new_in_XXX_version_1_2;
 in <span class="operator">&gt;</span><span class="operator">&gt;</span> other_interesting_data;</pre>
<p>You can select which byte order to use when serializing data. The default setting is big endian (MSB first). Changing it to little endian breaks the portability (unless the reader also changes to little endian). We recommend keeping this setting unless you have special requirements.</p>
<a name="raw"></a><a name="reading-and-writing-raw-binary-data"></a>
<h3>Reading and writing raw binary data</h3>
<p>You may wish to read/write your own raw binary data to/from the data stream directly. Data may be read from the stream into a preallocated <tt>char *</tt> using <a href="qdatastream.html#readRawData">readRawData</a>(). Similarly data can be written to the stream using <a href="qdatastream.html#writeRawData">writeRawData</a>(). Note that any encoding/decoding of the data must be done by you.</p>
<p>A similar pair of functions is <a href="qdatastream.html#readBytes">readBytes</a>() and <a href="qdatastream.html#writeBytes">writeBytes</a>(). These differ from their <i>raw</i> counterparts as follows: <a href="qdatastream.html#readBytes">readBytes</a>() reads a quint32 which is taken to be the length of the data to be read, then that number of bytes is read into the preallocated <tt>char *</tt>; <a href="qdatastream.html#writeBytes">writeBytes</a>() writes a quint32 containing the length of the data, followed by the data. Note that any encoding/decoding of the data (apart from the length quint32) must be done by you.</p>
<a name="reading-and-writing-qt-collection-classes"></a>
<h3>Reading and writing Qt collection classes</h3>
<p>The Qt container classes can also be serialized to a QDataStream. These include <a href="qlist.html">QList</a>, <a href="qlinkedlist.html">QLinkedList</a>, <a href="qvector.html">QVector</a>, <a href="qset.html">QSet</a>, <a href="qhash.html">QHash</a>, and <a href="qmap.html">QMap</a>. The stream operators are declared as non-members of the classes.</p>
<a name="serializing-qt-classes"></a><a name="reading-and-writing-other-qt-classes"></a>
<h3>Reading and writing other Qt classes.</h3>
<p>In addition to the overloaded stream operators documented here, any Qt classes that you might want to serialize to a QDataStream will have appropriate stream operators declared as non-member of the class:</p>
<pre class="cpp"> <span class="type">QDataStream</span> <span class="operator">&amp;</span><span class="keyword">operator</span><span class="operator">&lt;</span><span class="operator">&lt;</span>(<span class="type">QDataStream</span> <span class="operator">&amp;</span><span class="operator">,</span> <span class="keyword">const</span> <span class="type">QXxx</span> <span class="operator">&amp;</span>);
 <span class="type">QDataStream</span> <span class="operator">&amp;</span><span class="keyword">operator</span><span class="operator">&gt;</span><span class="operator">&gt;</span>(<span class="type">QDataStream</span> <span class="operator">&amp;</span><span class="operator">,</span> <span class="type">QXxx</span> <span class="operator">&amp;</span>);</pre>
<p>For example, here are the stream operators declared as non-members of the <a href="qimage.html">QImage</a> class:</p>
<pre class="cpp"> <span class="type">QDataStream</span> <span class="operator">&amp;</span> <span class="keyword">operator</span><span class="operator">&lt;</span><span class="operator">&lt;</span> (<span class="type">QDataStream</span><span class="operator">&amp;</span> stream<span class="operator">,</span> <span class="keyword">const</span> <span class="type"><a href="qimage.html">QImage</a></span><span class="operator">&amp;</span> image);
 <span class="type">QDataStream</span> <span class="operator">&amp;</span> <span class="keyword">operator</span><span class="operator">&gt;</span><span class="operator">&gt;</span> (<span class="type">QDataStream</span><span class="operator">&amp;</span> stream<span class="operator">,</span> <span class="type"><a href="qimage.html">QImage</a></span><span class="operator">&amp;</span> image);</pre>
<p>To see if your favorite Qt class has similar stream operators defined, check the <b>Related Non-Members</b> section of the class's documentation page.</p>
</div>
<p><b>See also </b><a href="qtextstream.html">QTextStream</a> and <a href="qvariant.html">QVariant</a>.</p>
<!-- @@@QDataStream -->
<div class="types">
<h2>Member Type Documentation</h2>
<!-- $$$ByteOrder$$$BigEndian$$$LittleEndian -->
<h3 class="fn"><a name="ByteOrder-enum"></a>enum QDataStream::<span class="name">ByteOrder</span></h3>
<p>The byte order used for reading/writing the data.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QDataStream::BigEndian</tt></td><td class="topAlign"><tt>QSysInfo::BigEndian</tt></td><td class="topAlign">Most significant byte first (the default)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::LittleEndian</tt></td><td class="topAlign"><tt>QSysInfo::LittleEndian</tt></td><td class="topAlign">Least significant byte first</td></tr>
</table>
<!-- @@@ByteOrder -->
<!-- $$$FloatingPointPrecision$$$SinglePrecision$$$DoublePrecision -->
<h3 class="fn"><a name="FloatingPointPrecision-enum"></a>enum QDataStream::<span class="name">FloatingPointPrecision</span></h3>
<p>The precision of floating point numbers used for reading/writing the data. This will only have an effect if the version of the data stream is <a href="qdatastream.html#Version-enum">Qt_4_6</a> or higher.</p>
<p><b>Warning:</b> The floating point precision must be set to the same value on the object that writes and the object that reads the data stream.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QDataStream::SinglePrecision</tt></td><td class="topAlign"><tt>0</tt></td><td class="topAlign">All floating point numbers in the data stream have 32-bit precision.</td></tr>
<tr><td class="topAlign"><tt>QDataStream::DoublePrecision</tt></td><td class="topAlign"><tt>1</tt></td><td class="topAlign">All floating point numbers in the data stream have 64-bit precision.</td></tr>
</table>
<p><b>See also </b><a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a>() and <a href="qdatastream.html#floatingPointPrecision">floatingPointPrecision</a>().</p>
<!-- @@@FloatingPointPrecision -->
<!-- $$$Status$$$Ok$$$ReadPastEnd$$$ReadCorruptData$$$WriteFailed -->
<h3 class="fn"><a name="Status-enum"></a>enum QDataStream::<span class="name">Status</span></h3>
<p>This enum describes the current status of the data stream.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QDataStream::Ok</tt></td><td class="topAlign"><tt>0</tt></td><td class="topAlign">The data stream is operating normally.</td></tr>
<tr><td class="topAlign"><tt>QDataStream::ReadPastEnd</tt></td><td class="topAlign"><tt>1</tt></td><td class="topAlign">The data stream has read past the end of the data in the underlying device.</td></tr>
<tr><td class="topAlign"><tt>QDataStream::ReadCorruptData</tt></td><td class="topAlign"><tt>2</tt></td><td class="topAlign">The data stream has read corrupt data.</td></tr>
<tr><td class="topAlign"><tt>QDataStream::WriteFailed</tt></td><td class="topAlign"><tt>3</tt></td><td class="topAlign">The data stream cannot write to the underlying device.</td></tr>
</table>
<!-- @@@Status -->
<!-- $$$Version$$$Qt_1_0$$$Qt_2_0$$$Qt_2_1$$$Qt_3_0$$$Qt_3_1$$$Qt_3_3$$$Qt_4_0$$$Qt_4_1$$$Qt_4_2$$$Qt_4_3$$$Qt_4_4$$$Qt_4_5$$$Qt_4_6$$$Qt_4_7$$$Qt_4_8 -->
<h3 class="fn"><a name="Version-enum"></a>enum QDataStream::<span class="name">Version</span></h3>
<p>This enum provides symbolic synonyms for the data serialization format version numbers.</p>
<table class="valuelist"><tr valign="top" class="odd"><th class="tblConst">Constant</th><th class="tblval">Value</th><th class="tbldscr">Description</th></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_1_0</tt></td><td class="topAlign"><tt>1</tt></td><td class="topAlign">Version 1 (Qt 1.x)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_2_0</tt></td><td class="topAlign"><tt>2</tt></td><td class="topAlign">Version 2 (Qt 2.0)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_2_1</tt></td><td class="topAlign"><tt>3</tt></td><td class="topAlign">Version 3 (Qt 2.1, 2.2, 2.3)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_3_0</tt></td><td class="topAlign"><tt>4</tt></td><td class="topAlign">Version 4 (Qt 3.0)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_3_1</tt></td><td class="topAlign"><tt>5</tt></td><td class="topAlign">Version 5 (Qt 3.1, 3.2)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_3_3</tt></td><td class="topAlign"><tt>6</tt></td><td class="topAlign">Version 6 (Qt 3.3)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_0</tt></td><td class="topAlign"><tt>7</tt></td><td class="topAlign">Version 7 (Qt 4.0, Qt 4.1)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_1</tt></td><td class="topAlign"><tt>Qt_4_0</tt></td><td class="topAlign">Version 7 (Qt 4.0, Qt 4.1)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_2</tt></td><td class="topAlign"><tt>8</tt></td><td class="topAlign">Version 8 (Qt 4.2)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_3</tt></td><td class="topAlign"><tt>9</tt></td><td class="topAlign">Version 9 (Qt 4.3)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_4</tt></td><td class="topAlign"><tt>10</tt></td><td class="topAlign">Version 10 (Qt 4.4)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_5</tt></td><td class="topAlign"><tt>11</tt></td><td class="topAlign">Version 11 (Qt 4.5)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_6</tt></td><td class="topAlign"><tt>12</tt></td><td class="topAlign">Version 12 (Qt 4.6, Qt 4.7, Qt 4.8)</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_7</tt></td><td class="topAlign"><tt>Qt_4_6</tt></td><td class="topAlign">Same as Qt_4_6.</td></tr>
<tr><td class="topAlign"><tt>QDataStream::Qt_4_8</tt></td><td class="topAlign"><tt>Qt_4_7 Qt_4_9 = Qt_4_8</tt></td><td class="topAlign">Same as Qt_4_6.</td></tr>
</table>
<p><b>See also </b><a href="qdatastream.html#setVersion">setVersion</a>() and <a href="qdatastream.html#version">version</a>().</p>
<!-- @@@Version -->
</div>
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QDataStream[overload1]$$$QDataStream -->
<h3 class="fn"><a name="QDataStream"></a>QDataStream::<span class="name">QDataStream</span> ()</h3>
<p>Constructs a data stream that has no I/O device.</p>
<p><b>See also </b><a href="qdatastream.html#setDevice">setDevice</a>().</p>
<!-- @@@QDataStream -->
<!-- $$$QDataStream$$$QDataStreamQIODevice* -->
<h3 class="fn"><a name="QDataStream-2"></a>QDataStream::<span class="name">QDataStream</span> ( <span class="type"><a href="qiodevice.html">QIODevice</a></span> * <i>d</i> )</h3>
<p>Constructs a data stream that uses the I/O device <i>d</i>.</p>
<p><b>Warning:</b> If you use <a href="porting4.html#qsocket">QSocket</a> or <a href="porting4.html#qsocketdevice">QSocketDevice</a> as the I/O device <i>d</i> for reading data, you must make sure that enough data is available on the socket for the operation to successfully proceed; <a href="qdatastream.html">QDataStream</a> does not have any means to handle or recover from short-reads.</p>
<p><b>See also </b><a href="qdatastream.html#setDevice">setDevice</a>() and <a href="qdatastream.html#device">device</a>().</p>
<!-- @@@QDataStream -->
<!-- $$$QDataStream$$$QDataStreamQByteArray*QIODevice::OpenMode -->
<h3 class="fn"><a name="QDataStream-4"></a>QDataStream::<span class="name">QDataStream</span> ( <span class="type"><a href="qbytearray.html">QByteArray</a></span> * <i>a</i>, <span class="type"><a href="qiodevice.html#OpenModeFlag-enum">QIODevice::OpenMode</a></span> <i>mode</i> )</h3>
<p>Constructs a data stream that operates on a byte array, <i>a</i>. The <i>mode</i> describes how the device is to be used.</p>
<p>Alternatively, you can use <a href="qdatastream.html">QDataStream</a>(const <a href="qbytearray.html">QByteArray</a> &amp;) if you just want to read from a byte array.</p>
<p>Since <a href="qbytearray.html">QByteArray</a> is not a <a href="qiodevice.html">QIODevice</a> subclass, internally a <a href="qbuffer.html">QBuffer</a> is created to wrap the byte array.</p>
<!-- @@@QDataStream -->
<!-- $$$QDataStream$$$QDataStreamconstQByteArray& -->
<h3 class="fn"><a name="QDataStream-5"></a>QDataStream::<span class="name">QDataStream</span> ( const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp; <i>a</i> )</h3>
<p>Constructs a read-only data stream that operates on byte array <i>a</i>. Use <a href="qdatastream.html">QDataStream</a>(<a href="qbytearray.html">QByteArray</a>*, int) if you want to write to a byte array.</p>
<p>Since <a href="qbytearray.html">QByteArray</a> is not a <a href="qiodevice.html">QIODevice</a> subclass, internally a <a href="qbuffer.html">QBuffer</a> is created to wrap the byte array.</p>
<!-- @@@QDataStream -->
<!-- $$$~QDataStream[overload1]$$$~QDataStream -->
<h3 class="fn"><a name="dtor.QDataStream"></a>QDataStream::<span class="name">~QDataStream</span> ()<tt> [virtual]</tt></h3>
<p>Destroys the data stream.</p>
<p>The destructor will not affect the current I/O device, unless it is an internal I/O device (e.g&#x2e; a <a href="qbuffer.html">QBuffer</a>) processing a <a href="qbytearray.html">QByteArray</a> passed in the <i>constructor</i>, in which case the internal I/O device is destroyed.</p>
<!-- @@@~QDataStream -->
<!-- $$$atEnd[overload1]$$$atEnd -->
<h3 class="fn"><a name="atEnd"></a><span class="type">bool</span> QDataStream::<span class="name">atEnd</span> () const</h3>
<p>Returns true if the I/O device has reached the end position (end of the stream or file) or if there is no I/O device set; otherwise returns false.</p>
<p><b>See also </b><a href="qiodevice.html#atEnd">QIODevice::atEnd</a>().</p>
<!-- @@@atEnd -->
<!-- $$$byteOrder[overload1]$$$byteOrder -->
<h3 class="fn"><a name="byteOrder"></a><span class="type"><a href="qdatastream.html#ByteOrder-enum">ByteOrder</a></span> QDataStream::<span class="name">byteOrder</span> () const</h3>
<p>Returns the current byte order setting -- either <a href="qdatastream.html#ByteOrder-enum">BigEndian</a> or <a href="qdatastream.html#ByteOrder-enum">LittleEndian</a>.</p>
<p><b>See also </b><a href="qdatastream.html#setByteOrder">setByteOrder</a>().</p>
<!-- @@@byteOrder -->
<!-- $$$device[overload1]$$$device -->
<h3 class="fn"><a name="device"></a><span class="type"><a href="qiodevice.html">QIODevice</a></span> * QDataStream::<span class="name">device</span> () const</h3>
<p>Returns the I/O device currently set, or 0 if no device is currently set.</p>
<p><b>See also </b><a href="qdatastream.html#setDevice">setDevice</a>().</p>
<!-- @@@device -->
<!-- $$$floatingPointPrecision[overload1]$$$floatingPointPrecision -->
<h3 class="fn"><a name="floatingPointPrecision"></a><span class="type"><a href="qdatastream.html#FloatingPointPrecision-enum">FloatingPointPrecision</a></span> QDataStream::<span class="name">floatingPointPrecision</span> () const</h3>
<p>Returns the floating point precision of the data stream.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also </b><a href="qdatastream.html#FloatingPointPrecision-enum">FloatingPointPrecision</a> and <a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a>().</p>
<!-- @@@floatingPointPrecision -->
<!-- $$$readBytes[overload1]$$$readByteschar*&uint& -->
<h3 class="fn"><a name="readBytes"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">readBytes</span> ( <span class="type">char</span> *&amp; <i>s</i>, <span class="type"><a href="qtglobal.html#uint-typedef">uint</a></span> &amp; <i>l</i> )</h3>
<p>Reads the buffer <i>s</i> from the stream and returns a reference to the stream.</p>
<p>The buffer <i>s</i> is allocated using <tt>new</tt>. Destroy it with the <tt>delete[]</tt> operator.</p>
<p>The <i>l</i> parameter is set to the length of the buffer. If the string read is empty, <i>l</i> is set to 0 and <i>s</i> is set to a null pointer.</p>
<p>The serialization format is a quint32 length specifier first, then <i>l</i> bytes of data.</p>
<p><b>See also </b><a href="qdatastream.html#readRawData">readRawData</a>() and <a href="qdatastream.html#writeBytes">writeBytes</a>().</p>
<!-- @@@readBytes -->
<!-- $$$readRawData[overload1]$$$readRawDatachar*int -->
<h3 class="fn"><a name="readRawData"></a><span class="type">int</span> QDataStream::<span class="name">readRawData</span> ( <span class="type">char</span> * <i>s</i>, <span class="type">int</span> <i>len</i> )</h3>
<p>Reads at most <i>len</i> bytes from the stream into <i>s</i> and returns the number of bytes read. If an error occurs, this function returns -1.</p>
<p>The buffer <i>s</i> must be preallocated. The data is <i>not</i> encoded.</p>
<p><b>See also </b><a href="qdatastream.html#readBytes">readBytes</a>(), <a href="qiodevice.html#read">QIODevice::read</a>(), and <a href="qdatastream.html#writeRawData">writeRawData</a>().</p>
<!-- @@@readRawData -->
<!-- $$$resetStatus[overload1]$$$resetStatus -->
<h3 class="fn"><a name="resetStatus"></a><span class="type">void</span> QDataStream::<span class="name">resetStatus</span> ()</h3>
<p>Resets the status of the data stream.</p>
<p><b>See also </b><a href="qdatastream.html#Status-enum">Status</a>, <a href="qdatastream.html#status">status</a>(), and <a href="qdatastream.html#setStatus">setStatus</a>().</p>
<!-- @@@resetStatus -->
<!-- $$$setByteOrder[overload1]$$$setByteOrderByteOrder -->
<h3 class="fn"><a name="setByteOrder"></a><span class="type">void</span> QDataStream::<span class="name">setByteOrder</span> ( <span class="type"><a href="qdatastream.html#ByteOrder-enum">ByteOrder</a></span> <i>bo</i> )</h3>
<p>Sets the serialization byte order to <i>bo</i>.</p>
<p>The <i>bo</i> parameter can be <a href="qdatastream.html#ByteOrder-enum">QDataStream::BigEndian</a> or <a href="qdatastream.html#ByteOrder-enum">QDataStream::LittleEndian</a>.</p>
<p>The default setting is big endian. We recommend leaving this setting unless you have special requirements.</p>
<p><b>See also </b><a href="qdatastream.html#byteOrder">byteOrder</a>().</p>
<!-- @@@setByteOrder -->
<!-- $$$setDevice[overload1]$$$setDeviceQIODevice* -->
<h3 class="fn"><a name="setDevice"></a><span class="type">void</span> QDataStream::<span class="name">setDevice</span> ( <span class="type"><a href="qiodevice.html">QIODevice</a></span> * <i>d</i> )</h3>
<p>void QDataStream::setDevice(<a href="qiodevice.html">QIODevice</a> *d)</p>
<p>Sets the I/O device to <i>d</i>, which can be 0 to unset to current I/O device.</p>
<p><b>See also </b><a href="qdatastream.html#device">device</a>().</p>
<!-- @@@setDevice -->
<!-- $$$setFloatingPointPrecision[overload1]$$$setFloatingPointPrecisionFloatingPointPrecision -->
<h3 class="fn"><a name="setFloatingPointPrecision"></a><span class="type">void</span> QDataStream::<span class="name">setFloatingPointPrecision</span> ( <span class="type"><a href="qdatastream.html#FloatingPointPrecision-enum">FloatingPointPrecision</a></span> <i>precision</i> )</h3>
<p>Sets the floating point precision of the data stream to <i>precision</i>. If the floating point precision is <a href="qdatastream.html#FloatingPointPrecision-enum">DoublePrecision</a> and the version of the data stream is <a href="qdatastream.html#Version-enum">Qt_4_6</a> or higher, all floating point numbers will be written and read with 64-bit precision. If the floating point precision is <a href="qdatastream.html#FloatingPointPrecision-enum">SinglePrecision</a> and the version is <a href="qdatastream.html#Version-enum">Qt_4_6</a> or higher, all floating point numbers will be written and read with 32-bit precision.</p>
<p>For versions prior to <a href="qdatastream.html#Version-enum">Qt_4_6</a>, the precision of floating point numbers in the data stream depends on the stream operator called.</p>
<p>The default is <a href="qdatastream.html#FloatingPointPrecision-enum">DoublePrecision</a>.</p>
<p><b>Warning:</b> This property must be set to the same value on the object that writes and the object that reads the data stream.</p>
<p>This function was introduced in Qt 4.6.</p>
<p><b>See also </b><a href="qdatastream.html#floatingPointPrecision">floatingPointPrecision</a>().</p>
<!-- @@@setFloatingPointPrecision -->
<!-- $$$setStatus[overload1]$$$setStatusStatus -->
<h3 class="fn"><a name="setStatus"></a><span class="type">void</span> QDataStream::<span class="name">setStatus</span> ( <span class="type"><a href="qdatastream.html#Status-enum">Status</a></span> <i>status</i> )</h3>
<p>Sets the status of the data stream to the <i>status</i> given.</p>
<p>Subsequent calls to setStatus() are ignored until <a href="qdatastream.html#resetStatus">resetStatus</a>() is called.</p>
<p><b>See also </b><a href="qdatastream.html#Status-enum">Status</a>, <a href="qdatastream.html#status">status</a>(), and <a href="qdatastream.html#resetStatus">resetStatus</a>().</p>
<!-- @@@setStatus -->
<!-- $$$setVersion[overload1]$$$setVersionint -->
<h3 class="fn"><a name="setVersion"></a><span class="type">void</span> QDataStream::<span class="name">setVersion</span> ( <span class="type">int</span> <i>v</i> )</h3>
<p>Sets the version number of the data serialization format to <i>v</i>.</p>
<p>You don't <i>have</i> to set a version if you are using the current version of Qt, but for your own custom binary formats we recommend that you do; see <a href="qdatastream.html#versioning">Versioning</a> in the Detailed Description.</p>
<p>To accommodate new functionality, the datastream serialization format of some Qt classes has changed in some versions of Qt. If you want to read data that was created by an earlier version of Qt, or write data that can be read by a program that was compiled with an earlier version of Qt, use this function to modify the serialization format used by <a href="qdatastream.html">QDataStream</a>.</p>
<table class="generic">
<thead><tr class="qt-style"><th >Qt Version</th><th ><a href="qdatastream.html">QDataStream</a> Version</th></tr></thead>
<tr valign="top" class="odd"><td >Qt 4.6</td><td >12</td></tr>
<tr valign="top" class="even"><td >Qt 4.5</td><td >11</td></tr>
<tr valign="top" class="odd"><td >Qt 4.4</td><td >10</td></tr>
<tr valign="top" class="even"><td >Qt 4.3</td><td >9</td></tr>
<tr valign="top" class="odd"><td >Qt 4.2</td><td >8</td></tr>
<tr valign="top" class="even"><td >Qt 4.0, 4.1</td><td >7</td></tr>
<tr valign="top" class="odd"><td >Qt 3.3</td><td >6</td></tr>
<tr valign="top" class="even"><td >Qt 3.1, 3.2</td><td >5</td></tr>
<tr valign="top" class="odd"><td >Qt 3.0</td><td >4</td></tr>
<tr valign="top" class="even"><td >Qt 2.1, 2.2, 2.3</td><td >3</td></tr>
<tr valign="top" class="odd"><td >Qt 2.0</td><td >2</td></tr>
<tr valign="top" class="even"><td >Qt 1.x</td><td >1</td></tr>
</table>
<p>The <a href="qdatastream.html#Version-enum">Version</a> enum provides symbolic constants for the different versions of Qt. For example:</p>
<pre class="cpp"> <span class="type"><a href="qdatastream.html">QDataStream</a></span> out(file);
 out<span class="operator">.</span>setVersion(<span class="type"><a href="qdatastream.html">QDataStream</a></span><span class="operator">::</span>Qt_4_0);</pre>
<p><b>See also </b><a href="qdatastream.html#version">version</a>() and <a href="qdatastream.html#Version-enum">Version</a>.</p>
<!-- @@@setVersion -->
<!-- $$$skipRawData[overload1]$$$skipRawDataint -->
<h3 class="fn"><a name="skipRawData"></a><span class="type">int</span> QDataStream::<span class="name">skipRawData</span> ( <span class="type">int</span> <i>len</i> )</h3>
<p>Skips <i>len</i> bytes from the device. Returns the number of bytes actually skipped, or -1 on error.</p>
<p>This is equivalent to calling <a href="qdatastream.html#readRawData">readRawData</a>() on a buffer of length <i>len</i> and ignoring the buffer.</p>
<p>This function was introduced in Qt 4.1.</p>
<p><b>See also </b><a href="qiodevice.html#seek">QIODevice::seek</a>().</p>
<!-- @@@skipRawData -->
<!-- $$$status[overload1]$$$status -->
<h3 class="fn"><a name="status"></a><span class="type"><a href="qdatastream.html#Status-enum">Status</a></span> QDataStream::<span class="name">status</span> () const</h3>
<p>Returns the status of the data stream.</p>
<p><b>See also </b><a href="qdatastream.html#Status-enum">Status</a>, <a href="qdatastream.html#setStatus">setStatus</a>(), and <a href="qdatastream.html#resetStatus">resetStatus</a>().</p>
<!-- @@@status -->
<!-- $$$version[overload1]$$$version -->
<h3 class="fn"><a name="version"></a><span class="type">int</span> QDataStream::<span class="name">version</span> () const</h3>
<p>Returns the version number of the data serialization format.</p>
<p><b>See also </b><a href="qdatastream.html#setVersion">setVersion</a>() and <a href="qdatastream.html#Version-enum">Version</a>.</p>
<!-- @@@version -->
<!-- $$$writeBytes[overload1]$$$writeBytesconstchar*uint -->
<h3 class="fn"><a name="writeBytes"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">writeBytes</span> ( const <span class="type">char</span> * <i>s</i>, <span class="type"><a href="qtglobal.html#uint-typedef">uint</a></span> <i>len</i> )</h3>
<p>Writes the length specifier <i>len</i> and the buffer <i>s</i> to the stream and returns a reference to the stream.</p>
<p>The <i>len</i> is serialized as a quint32, followed by <i>len</i> bytes from <i>s</i>. Note that the data is <i>not</i> encoded.</p>
<p><b>See also </b><a href="qdatastream.html#writeRawData">writeRawData</a>() and <a href="qdatastream.html#readBytes">readBytes</a>().</p>
<!-- @@@writeBytes -->
<!-- $$$writeRawData[overload1]$$$writeRawDataconstchar*int -->
<h3 class="fn"><a name="writeRawData"></a><span class="type">int</span> QDataStream::<span class="name">writeRawData</span> ( const <span class="type">char</span> * <i>s</i>, <span class="type">int</span> <i>len</i> )</h3>
<p>Writes <i>len</i> bytes from <i>s</i> to the stream. Returns the number of bytes actually written, or -1 on error. The data is <i>not</i> encoded.</p>
<p><b>See also </b><a href="qdatastream.html#writeBytes">writeBytes</a>(), <a href="qiodevice.html#write">QIODevice::write</a>(), and <a href="qdatastream.html#readRawData">readRawData</a>().</p>
<!-- @@@writeRawData -->
<!-- $$$operator<<[overload1]$$$operator<<qint8 -->
<h3 class="fn"><a name="operator-lt-lt"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#qint8-typedef">qint8</a></span> <i>i</i> )</h3>
<p>Writes a signed byte, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<bool -->
<h3 class="fn"><a name="operator-lt-lt-2"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type">bool</span> <i>i</i> )</h3>
<p>Writes a boolean value, <i>i</i>, to the stream. Returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<quint8 -->
<h3 class="fn"><a name="operator-lt-lt-3"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#quint8-typedef">quint8</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes an unsigned byte, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<quint16 -->
<h3 class="fn"><a name="operator-lt-lt-4"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes an unsigned 16-bit integer, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<qint16 -->
<h3 class="fn"><a name="operator-lt-lt-5"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#qint16-typedef">qint16</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes a signed 16-bit integer, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<qint32 -->
<h3 class="fn"><a name="operator-lt-lt-6"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#qint32-typedef">qint32</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes a signed 32-bit integer, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<quint64 -->
<h3 class="fn"><a name="operator-lt-lt-7"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#quint64-typedef">quint64</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes an unsigned 64-bit integer, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<qint64 -->
<h3 class="fn"><a name="operator-lt-lt-8"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes a signed 64-bit integer, <i>i</i>, to the stream and returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<quint32 -->
<h3 class="fn"><a name="operator-lt-lt-9"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type"><a href="qtglobal.html#quint32-typedef">quint32</a></span> <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes an unsigned integer, <i>i</i>, to the stream as a 32-bit unsigned integer (quint32). Returns a reference to the stream.</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<float -->
<h3 class="fn"><a name="operator-lt-lt-10"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type">float</span> <i>f</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes a floating point number, <i>f</i>, to the stream using the standard IEEE 754 format. Returns a reference to the stream.</p>
<p><b>See also </b><a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a>().</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<double -->
<h3 class="fn"><a name="operator-lt-lt-11"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( <span class="type">double</span> <i>f</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes a floating point number, <i>f</i>, to the stream using the standard IEEE 754 format. Returns a reference to the stream.</p>
<p><b>See also </b><a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a>().</p>
<!-- @@@operator<< -->
<!-- $$$operator<<$$$operator<<constchar* -->
<h3 class="fn"><a name="operator-lt-lt-12"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&lt;&lt;</span> ( const <span class="type">char</span> * <i>s</i> )</h3>
<p>This is an overloaded function.</p>
<p>Writes the '\0'-terminated string <i>s</i> to the stream and returns a reference to the stream.</p>
<p>The string is serialized using <a href="qdatastream.html#writeBytes">writeBytes</a>().</p>
<!-- @@@operator<< -->
<!-- $$$operator>>[overload1]$$$operator>>qint8& -->
<h3 class="fn"><a name="operator-gt-gt"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#qint8-typedef">qint8</a></span> &amp; <i>i</i> )</h3>
<p>Reads a signed byte from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>bool& -->
<h3 class="fn"><a name="operator-gt-gt-2"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type">bool</span> &amp; <i>i</i> )</h3>
<p>Reads a boolean value from the stream into <i>i</i>. Returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>quint8& -->
<h3 class="fn"><a name="operator-gt-gt-3"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#quint8-typedef">quint8</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads an unsigned byte from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>quint16& -->
<h3 class="fn"><a name="operator-gt-gt-4"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#quint16-typedef">quint16</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads an unsigned 16-bit integer from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>qint16& -->
<h3 class="fn"><a name="operator-gt-gt-5"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#qint16-typedef">qint16</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads a signed 16-bit integer from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>quint32& -->
<h3 class="fn"><a name="operator-gt-gt-6"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#quint32-typedef">quint32</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads an unsigned 32-bit integer from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>qint32& -->
<h3 class="fn"><a name="operator-gt-gt-7"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#qint32-typedef">qint32</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads a signed 32-bit integer from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>quint64& -->
<h3 class="fn"><a name="operator-gt-gt-8"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#quint64-typedef">quint64</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads an unsigned 64-bit integer from the stream, into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>qint64& -->
<h3 class="fn"><a name="operator-gt-gt-9"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> &amp; <i>i</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads a signed 64-bit integer from the stream into <i>i</i>, and returns a reference to the stream.</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>float& -->
<h3 class="fn"><a name="operator-gt-gt-10"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type">float</span> &amp; <i>f</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads a floating point number from the stream into <i>f</i>, using the standard IEEE 754 format. Returns a reference to the stream.</p>
<p><b>See also </b><a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a>().</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>double& -->
<h3 class="fn"><a name="operator-gt-gt-11"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type">double</span> &amp; <i>f</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads a floating point number from the stream into <i>f</i>, using the standard IEEE 754 format. Returns a reference to the stream.</p>
<p><b>See also </b><a href="qdatastream.html#setFloatingPointPrecision">setFloatingPointPrecision</a>().</p>
<!-- @@@operator>> -->
<!-- $$$operator>>$$$operator>>char*& -->
<h3 class="fn"><a name="operator-gt-gt-12"></a><span class="type">QDataStream</span> &amp; QDataStream::<span class="name">operator&gt;&gt;</span> ( <span class="type">char</span> *&amp; <i>s</i> )</h3>
<p>This is an overloaded function.</p>
<p>Reads the '\0'-terminated string <i>s</i> from the stream and returns a reference to the stream.</p>
<p>Space for the string is allocated using <tt>new</tt> -- the caller must destroy it with <tt>delete[]</tt>.</p>
<!-- @@@operator>> -->
</div>
  <div class="ft">
    <span></span>
  </div>
</div> 
<div class="footer">
    <p>
      <acronym title="Copyright">&copy;</acronym> 2012 Nokia Corporation and/or its
      subsidiaries. Documentation contributions included herein are the copyrights of
      their respective owners.</p>
    <br />
    <p>
      The documentation provided herein is licensed under the terms of the
      <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation
      License version 1.3</a> as published by the Free Software Foundation.</p>
    <p>
      Documentation sources may be obtained from <a href="http://www.qt-project.org">
      www.qt-project.org</a>.</p>
    <br />
    <p>
      Nokia, Qt and their respective logos are trademarks of Nokia Corporation 
      in Finland and/or other countries worldwide. All other trademarks are property
      of their respective owners. <a title="Privacy Policy"
      href="http://en.gitorious.org/privacy_policy/">Privacy Policy</a></p>
</div>
</body>
</html>