[190] | 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"><!--
|
---|
| 8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
| 9 | a:link { color: #004faf; text-decoration: none }
|
---|
| 10 | a:visited { color: #672967; text-decoration: none }
|
---|
| 11 | body { 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 Classes</font></a>
|
---|
| 23 | | <a href="mainclasses.html">
|
---|
| 24 | <font color="#004faf">Main 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 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
|
---|
| 35 | to 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 <<a href="qdatastream-h.html">qdatastream.h</a>></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 * d )</li>
|
---|
| 44 | <li class=fn><a href="#QDataStream-3"><b>QDataStream</b></a> ( QByteArray a, int 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 * 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 <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 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 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 v )</li>
|
---|
| 58 | <li class=fn>QDataStream & <a href="#operator-gt-gt"><b>operator>></b></a> ( Q_INT8 & i )</li>
|
---|
| 59 | <li class=fn>QDataStream & <a href="#operator-gt-gt-2"><b>operator>></b></a> ( Q_UINT8 & i )</li>
|
---|
| 60 | <li class=fn>QDataStream & <a href="#operator-gt-gt-3"><b>operator>></b></a> ( Q_INT16 & i )</li>
|
---|
| 61 | <li class=fn>QDataStream & <a href="#operator-gt-gt-4"><b>operator>></b></a> ( Q_UINT16 & i )</li>
|
---|
| 62 | <li class=fn>QDataStream & <a href="#operator-gt-gt-5"><b>operator>></b></a> ( Q_INT32 & i )</li>
|
---|
| 63 | <li class=fn>QDataStream & <a href="#operator-gt-gt-6"><b>operator>></b></a> ( Q_UINT32 & i )</li>
|
---|
| 64 | <li class=fn>QDataStream & <a href="#operator-gt-gt-7"><b>operator>></b></a> ( Q_INT64 & i )</li>
|
---|
| 65 | <li class=fn>QDataStream & <a href="#operator-gt-gt-8"><b>operator>></b></a> ( Q_UINT64 & i )</li>
|
---|
| 66 | <li class=fn>QDataStream & <a href="#operator-gt-gt-9"><b>operator>></b></a> ( Q_LONG & i )</li>
|
---|
| 67 | <li class=fn>QDataStream & <a href="#operator-gt-gt-a"><b>operator>></b></a> ( Q_ULONG & i )</li>
|
---|
| 68 | <li class=fn>QDataStream & <a href="#operator-gt-gt-b"><b>operator>></b></a> ( float & f )</li>
|
---|
| 69 | <li class=fn>QDataStream & <a href="#operator-gt-gt-c"><b>operator>></b></a> ( double & f )</li>
|
---|
| 70 | <li class=fn>QDataStream & <a href="#operator-gt-gt-d"><b>operator>></b></a> ( char *& s )</li>
|
---|
| 71 | <li class=fn>QDataStream & <a href="#operator-lt-lt"><b>operator<<</b></a> ( Q_INT8 i )</li>
|
---|
| 72 | <li class=fn>QDataStream & <a href="#operator-lt-lt-2"><b>operator<<</b></a> ( Q_UINT8 i )</li>
|
---|
| 73 | <li class=fn>QDataStream & <a href="#operator-lt-lt-3"><b>operator<<</b></a> ( Q_INT16 i )</li>
|
---|
| 74 | <li class=fn>QDataStream & <a href="#operator-lt-lt-4"><b>operator<<</b></a> ( Q_UINT16 i )</li>
|
---|
| 75 | <li class=fn>QDataStream & <a href="#operator-lt-lt-5"><b>operator<<</b></a> ( Q_INT32 i )</li>
|
---|
| 76 | <li class=fn>QDataStream & <a href="#operator-lt-lt-6"><b>operator<<</b></a> ( Q_UINT32 i )</li>
|
---|
| 77 | <li class=fn>QDataStream & <a href="#operator-lt-lt-7"><b>operator<<</b></a> ( Q_INT64 i )</li>
|
---|
| 78 | <li class=fn>QDataStream & <a href="#operator-lt-lt-8"><b>operator<<</b></a> ( Q_UINT64 i )</li>
|
---|
| 79 | <li class=fn>QDataStream & <a href="#operator-lt-lt-9"><b>operator<<</b></a> ( Q_LONG i )</li>
|
---|
| 80 | <li class=fn>QDataStream & <a href="#operator-lt-lt-a"><b>operator<<</b></a> ( Q_ULONG i )</li>
|
---|
| 81 | <li class=fn>QDataStream & <a href="#operator-lt-lt-b"><b>operator<<</b></a> ( float f )</li>
|
---|
| 82 | <li class=fn>QDataStream & <a href="#operator-lt-lt-c"><b>operator<<</b></a> ( double f )</li>
|
---|
| 83 | <li class=fn>QDataStream & <a href="#operator-lt-lt-d"><b>operator<<</b></a> ( const char * s )</li>
|
---|
| 84 | <li class=fn>QDataStream & <a href="#readBytes"><b>readBytes</b></a> ( char *& s, uint & l )</li>
|
---|
| 85 | <li class=fn>QDataStream & <a href="#readRawBytes"><b>readRawBytes</b></a> ( char * s, uint len )</li>
|
---|
| 86 | <li class=fn>QDataStream & <a href="#writeBytes"><b>writeBytes</b></a> ( const char * s, uint len )</li>
|
---|
| 87 | <li class=fn>QDataStream & <a href="#writeRawBytes"><b>writeRawBytes</b></a> ( const char * s, uint len )</li>
|
---|
| 88 | </ul>
|
---|
| 89 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
| 90 |
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | The QDataStream class provides serialization of binary data
|
---|
| 94 | to a <a href="qiodevice.html">QIODevice</a>.
|
---|
| 95 | <p>
|
---|
| 96 | <p> A data stream is a binary stream of encoded information which is
|
---|
| 97 | 100% independent of the host computer's operating system, CPU or
|
---|
| 98 | byte order. For example, a data stream that is written by a PC
|
---|
| 99 | under 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
|
---|
| 102 | stream, see <a href="qtextstream.html">QTextStream</a>.
|
---|
| 103 | <p> The QDataStream class implements the serialization of C++'s basic
|
---|
| 104 | data types, like <tt>char</tt>, <tt>short</tt>, <tt>int</tt>, <tt>char*</tt>, etc.
|
---|
| 105 | Serialization of more complex data is accomplished by breaking up
|
---|
| 106 | the data into primitive units.
|
---|
| 107 | <p> A data stream cooperates closely with a QIODevice. A QIODevice
|
---|
| 108 | represents an input/output medium one can read data from and write
|
---|
| 109 | data 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( &file ); // we will serialize the data into the file
|
---|
| 115 | stream << "the answer is"; // serialize a string
|
---|
| 116 | stream << (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( &file ); // read the data serialized from the file
|
---|
| 124 | <a href="qstring.html">QString</a> str;
|
---|
| 125 | Q_INT32 a;
|
---|
| 126 | stream >> str >> a; // extract "the answer is" and 42
|
---|
| 127 | </pre>
|
---|
| 128 |
|
---|
| 129 | <p> Each item written to the stream is written in a predefined binary
|
---|
| 130 | format that varies depending on the item's type. Supported Qt
|
---|
| 131 | 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>,
|
---|
| 132 | <a href="qvariant.html">QVariant</a> and many others. For the complete list of all Qt types
|
---|
| 133 | supporting 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
|
---|
| 135 | writing, and to read back into the same Qt integer type. This
|
---|
| 136 | ensures that you get integers of the size you want and insulates
|
---|
| 137 | you from compiler and platform differences.
|
---|
| 138 | <p> To take one example, a <tt>char*</tt> string is written as a 32-bit
|
---|
| 139 | integer equal to the length of the string including the NUL byte
|
---|
| 140 | ('\0'), followed by all the characters of the string including the
|
---|
| 141 | NUL byte. When reading a <tt>char*</tt> string, 4 bytes are read to
|
---|
| 142 | create 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
|
---|
| 145 | changed 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
|
---|
| 148 | Qt use <a href="#setVersion">setVersion</a>().
|
---|
| 149 | <p> If you want the data to be human-readable, e.g. for debugging, you
|
---|
| 150 | can set the data stream into printable data mode with
|
---|
| 151 | <a href="#setPrintableData">setPrintableData</a>(). The data is then written slower, in a bloated
|
---|
| 152 | but human readable format.
|
---|
| 153 | <p> If you are producing a new binary data format, such as a file
|
---|
| 154 | format for documents created by your application, you could use a
|
---|
| 155 | QDataStream to write the data in a portable format. Typically, you
|
---|
| 156 | would write a brief header containing a magic string and a version
|
---|
| 157 | number 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( &file );
|
---|
| 162 |
|
---|
| 163 | // Write a header with a "magic number" and a version
|
---|
| 164 | stream << (Q_UINT32)0xA0B0C0D0;
|
---|
| 165 | stream << (Q_INT32)123;
|
---|
| 166 |
|
---|
| 167 | // Write the data
|
---|
| 168 | stream << [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( &file );
|
---|
| 176 |
|
---|
| 177 | // Read and check the header
|
---|
| 178 | Q_UINT32 magic;
|
---|
| 179 | stream >> magic;
|
---|
| 180 | if ( magic != 0xA0B0C0D0 )
|
---|
| 181 | return XXX_BAD_FILE_FORMAT;
|
---|
| 182 |
|
---|
| 183 | // Read the version
|
---|
| 184 | Q_INT32 version;
|
---|
| 185 | stream >> version;
|
---|
| 186 | if ( version < 100 )
|
---|
| 187 | return XXX_BAD_FILE_TOO_OLD;
|
---|
| 188 | if ( version > 123 )
|
---|
| 189 | return XXX_BAD_FILE_TOO_NEW;
|
---|
| 190 | if ( version <= 110 )
|
---|
| 191 | stream.<a href="#setVersion">setVersion</a>(1);
|
---|
| 192 |
|
---|
| 193 | // Read the data
|
---|
| 194 | stream >> [lots of interesting data];
|
---|
| 195 | if ( version > 120 )
|
---|
| 196 | stream >> [data new in XXX version 1.2];
|
---|
| 197 | stream >> [other interesting data];
|
---|
| 198 | </pre>
|
---|
| 199 |
|
---|
| 200 | <p> You can select which byte order to use when serializing data. The
|
---|
| 201 | default setting is big endian (MSB first). Changing it to little
|
---|
| 202 | endian breaks the portability (unless the reader also changes to
|
---|
| 203 | little endian). We recommend keeping this setting unless you have
|
---|
| 204 | special 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
|
---|
| 209 | data stream directly. Data may be read from the stream into a
|
---|
| 210 | preallocated char* using <a href="#readRawBytes">readRawBytes</a>(). Similarly data can be
|
---|
| 211 | written to the stream using <a href="#writeRawBytes">writeRawBytes</a>(). Notice that any
|
---|
| 212 | encoding/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
|
---|
| 214 | differ from their <em>raw</em> counterparts as follows: readBytes()
|
---|
| 215 | reads a Q_UINT32 which is taken to be the length of the data to be
|
---|
| 216 | read, then that number of bytes is read into the preallocated
|
---|
| 217 | char*; writeBytes() writes a Q_UINT32 containing the length of the
|
---|
| 218 | data, followed by the data. Notice that any encoding/decoding of
|
---|
| 219 | the 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>
|
---|
| 233 | Constructs 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> * d )
|
---|
| 237 | </h3>
|
---|
| 238 | Constructs 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>
|
---|
| 240 | for reading data, you must make sure that enough data is available
|
---|
| 241 | on the socket for the operation to successfully proceed;
|
---|
| 242 | QDataStream does not have any means to handle or recover from
|
---|
| 243 | short-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> a, int mode )
|
---|
| 247 | </h3>
|
---|
| 248 | Constructs a data stream that operates on a byte array, <em>a</em>,
|
---|
| 249 | through 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 >> [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>
|
---|
| 265 | Destroys the data stream.
|
---|
| 266 | <p> The destructor will not affect the current IO device, unless it is
|
---|
| 267 | an 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
|
---|
| 273 | the stream or file) or if there is no IO device set; otherwise
|
---|
| 274 | returns FALSE, i.e. if the current position of the IO device is
|
---|
| 275 | before 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> * <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
|
---|
| 295 | stream 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
|
---|
| 297 | device 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
|
---|
| 304 | returns FALSE.
|
---|
| 305 | <p> <p>See also <a href="#setPrintableData">setPrintableData</a>().
|
---|
| 306 |
|
---|
| 307 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt"></a>QDataStream::operator<< ( Q_INT8 i )
|
---|
| 308 | </h3>
|
---|
| 309 | Writes a signed byte, <em>i</em>, to the stream and returns a reference
|
---|
| 310 | to the stream.
|
---|
| 311 |
|
---|
| 312 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-2"></a>QDataStream::operator<< ( Q_UINT8 i )
|
---|
| 313 | </h3>
|
---|
| 314 | This 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
|
---|
| 316 | reference to the stream.
|
---|
| 317 |
|
---|
| 318 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-3"></a>QDataStream::operator<< ( Q_INT16 i )
|
---|
| 319 | </h3>
|
---|
| 320 | This 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
|
---|
| 322 | reference to the stream.
|
---|
| 323 |
|
---|
| 324 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-4"></a>QDataStream::operator<< ( Q_UINT16 i )
|
---|
| 325 | </h3>
|
---|
| 326 | This 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
|
---|
| 328 | a reference to the stream.
|
---|
| 329 |
|
---|
| 330 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-5"></a>QDataStream::operator<< ( Q_INT32 i )
|
---|
| 331 | </h3>
|
---|
| 332 | This 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
|
---|
| 334 | reference to the stream.
|
---|
| 335 |
|
---|
| 336 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-6"></a>QDataStream::operator<< ( Q_UINT32 i )
|
---|
| 337 | </h3>
|
---|
| 338 | This 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
|
---|
| 340 | unsigned integer (Q_UINT32). Returns a reference to the stream.
|
---|
| 341 |
|
---|
| 342 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-7"></a>QDataStream::operator<< ( Q_INT64 i )
|
---|
| 343 | </h3>
|
---|
| 344 | This 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
|
---|
| 346 | reference to the stream.
|
---|
| 347 |
|
---|
| 348 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-8"></a>QDataStream::operator<< ( Q_UINT64 i )
|
---|
| 349 | </h3>
|
---|
| 350 | This 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
|
---|
| 352 | reference to the stream.
|
---|
| 353 |
|
---|
| 354 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-9"></a>QDataStream::operator<< ( Q_LONG i )
|
---|
| 355 | </h3>
|
---|
| 356 | This 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
|
---|
| 358 | stream and returns a reference to the stream.
|
---|
| 359 |
|
---|
| 360 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-a"></a>QDataStream::operator<< ( Q_ULONG i )
|
---|
| 361 | </h3>
|
---|
| 362 | This 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
|
---|
| 364 | the stream and returns a reference to the stream.
|
---|
| 365 |
|
---|
| 366 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-b"></a>QDataStream::operator<< ( float f )
|
---|
| 367 | </h3>
|
---|
| 368 | This 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
|
---|
| 370 | the standard IEEE754 format. Returns a reference to the stream.
|
---|
| 371 |
|
---|
| 372 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-c"></a>QDataStream::operator<< ( double f )
|
---|
| 373 | </h3>
|
---|
| 374 | This 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
|
---|
| 376 | the standard IEEE754 format. Returns a reference to the stream.
|
---|
| 377 |
|
---|
| 378 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-lt-lt-d"></a>QDataStream::operator<< ( const char * s )
|
---|
| 379 | </h3>
|
---|
| 380 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
| 381 | <p> Writes the '\0'-terminated string <em>s</em> to the stream and returns a
|
---|
| 382 | reference 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> & <a name="operator-gt-gt"></a>QDataStream::operator>> ( Q_INT8 & i )
|
---|
| 386 | </h3>
|
---|
| 387 | Reads a signed byte from the stream into <em>i</em>, and returns a
|
---|
| 388 | reference to the stream.
|
---|
| 389 |
|
---|
| 390 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-2"></a>QDataStream::operator>> ( Q_UINT8 & i )
|
---|
| 391 | </h3>
|
---|
| 392 | This 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
|
---|
| 394 | reference to the stream.
|
---|
| 395 |
|
---|
| 396 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-3"></a>QDataStream::operator>> ( Q_INT16 & i )
|
---|
| 397 | </h3>
|
---|
| 398 | This 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
|
---|
| 400 | returns a reference to the stream.
|
---|
| 401 |
|
---|
| 402 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-4"></a>QDataStream::operator>> ( Q_UINT16 & i )
|
---|
| 403 | </h3>
|
---|
| 404 | This 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
|
---|
| 406 | returns a reference to the stream.
|
---|
| 407 |
|
---|
| 408 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-5"></a>QDataStream::operator>> ( Q_INT32 & i )
|
---|
| 409 | </h3>
|
---|
| 410 | This 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
|
---|
| 412 | returns a reference to the stream.
|
---|
| 413 |
|
---|
| 414 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-6"></a>QDataStream::operator>> ( Q_UINT32 & i )
|
---|
| 415 | </h3>
|
---|
| 416 | This 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
|
---|
| 418 | returns a reference to the stream.
|
---|
| 419 |
|
---|
| 420 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-7"></a>QDataStream::operator>> ( Q_INT64 & i )
|
---|
| 421 | </h3>
|
---|
| 422 | This 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
|
---|
| 424 | returns a reference to the stream.
|
---|
| 425 |
|
---|
| 426 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-8"></a>QDataStream::operator>> ( Q_UINT64 & i )
|
---|
| 427 | </h3>
|
---|
| 428 | This 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
|
---|
| 430 | returns a reference to the stream.
|
---|
| 431 |
|
---|
| 432 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-9"></a>QDataStream::operator>> ( Q_LONG & i )
|
---|
| 433 | </h3>
|
---|
| 434 | This 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
|
---|
| 436 | into <em>i</em>, and returns a reference to the stream.
|
---|
| 437 | <p>
|
---|
| 438 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-a"></a>QDataStream::operator>> ( Q_ULONG & i )
|
---|
| 439 | </h3>
|
---|
| 440 | This 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
|
---|
| 442 | stream, into <em>i</em>, and returns a reference to the stream.
|
---|
| 443 |
|
---|
| 444 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-b"></a>QDataStream::operator>> ( float & f )
|
---|
| 445 | </h3>
|
---|
| 446 | This 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>,
|
---|
| 448 | using the standard IEEE754 format. Returns a reference to the
|
---|
| 449 | stream.
|
---|
| 450 |
|
---|
| 451 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-c"></a>QDataStream::operator>> ( double & f )
|
---|
| 452 | </h3>
|
---|
| 453 | This 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>,
|
---|
| 455 | using the standard IEEE754 format. Returns a reference to the
|
---|
| 456 | stream.
|
---|
| 457 |
|
---|
| 458 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="operator-gt-gt-d"></a>QDataStream::operator>> ( char *& s )
|
---|
| 459 | </h3>
|
---|
| 460 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
| 461 | <p> Reads the '\0'-terminated string <em>s</em> from the stream and returns
|
---|
| 462 | a reference to the stream.
|
---|
| 463 | <p> Space for the string is allocated using <tt>new</tt> -- the caller must
|
---|
| 464 | destroy it with delete[].
|
---|
| 465 |
|
---|
| 466 | <h3 class=fn><a href="qdatastream.html">QDataStream</a> & <a name="readBytes"></a>QDataStream::readBytes ( char *& s, uint & l )
|
---|
| 467 | </h3>
|
---|
| 468 | Reads the buffer <em>s</em> from the stream and returns a reference to
|
---|
| 469 | the 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
|
---|
| 471 | allocated, <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,
|
---|
| 474 | then <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> & <a name="readRawBytes"></a>QDataStream::readRawBytes ( char * s, uint len )
|
---|
| 478 | </h3>
|
---|
| 479 | Reads <em>len</em> bytes from the stream into <em>s</em> and returns a
|
---|
| 480 | reference 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 bo )
|
---|
| 485 | </h3>
|
---|
| 486 | Sets 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
|
---|
| 489 | setting 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> * d )
|
---|
| 493 | </h3>
|
---|
| 494 | void <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 enable )
|
---|
| 499 | </h3>
|
---|
| 500 |
|
---|
| 501 | <p> If <em>enable</em> is TRUE, data will be output in a human readable
|
---|
| 502 | format. If <em>enable</em> is FALSE, data will be output in a binary
|
---|
| 503 | format.
|
---|
| 504 | <p> If <em>enable</em> is TRUE, the write functions will generate output
|
---|
| 505 | that consists of printable characters (7 bit ASCII). This output
|
---|
| 506 | will typically be a lot larger than the default binary output, and
|
---|
| 507 | consequently 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 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
|
---|
| 515 | version of Qt.
|
---|
| 516 | <p> In order to accommodate new functionality, the datastream
|
---|
| 517 | serialization format of some Qt classes has changed in some
|
---|
| 518 | versions of Qt. If you want to read data that was created by an
|
---|
| 519 | earlier version of Qt, or write data that can be read by a program
|
---|
| 520 | that was compiled with an earlier version of Qt, use this function
|
---|
| 521 | to 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>
|
---|
| 536 | Unsets 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
|
---|
| 543 | 3.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> & <a name="writeBytes"></a>QDataStream::writeBytes ( const char * s, uint len )
|
---|
| 547 | </h3>
|
---|
| 548 | Writes the length specifier <em>len</em> and the buffer <em>s</em> to the
|
---|
| 549 | stream 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
|
---|
| 551 | from <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> & <a name="writeRawBytes"></a>QDataStream::writeRawBytes ( const char * s, uint len )
|
---|
| 555 | </h3>
|
---|
| 556 | Writes <em>len</em> bytes from <em>s</em> to the stream and returns a
|
---|
| 557 | reference 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>
|
---|
| 562 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
| 563 | Copyright © 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 © 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>
|
---|