📄 qdatastream.3qt
字号:
// Read and check the header.br Q_UINT32 magic;.br s >> magic;.br if ( magic != 0xa0b0c0d0 ).br return XXX_BAD_FILE_FORMAT;.br.br // Read the version.br Q_INT32 version;.br s >> version;.br if ( version < 100 ).br return XXX_BAD_FILE_TOO_OLD;.br if ( version > 123 ).br return XXX_BAD_FILE_TOO_NEW;.br if ( version <= 110 ).br s.setVersion(1);.br.br // Read the data.br s >> [lots of interesting data];.br if ( version > 120 ).br s >> [data new in XXX version 1.2];.br s >> [other interesting data];.fi.PPSee also QTextStream and QVariant..SH MEMBER FUNCTION DOCUMENTATION.SH "QDataStream::QDataStream ()"Constructs a data stream that has no IO device..PPSee also setDevice()..SH "QDataStream::QDataStream ( QByteArray a, int mode )"Constructs a data stream that operates on a byte array through an internal QBuffer device..PPExample:.PP.nf.br static char bindata[] = { 231, 1, 44, ... };.br QByteArray a;.br a.setRawData( bindata, sizeof(bindata) ); // a points to bindata.br QDataStream s( a, IO_ReadOnly ); // open on a's data.br s >> [something]; // read raw bindata.br a.resetRawData( bindata, sizeof(bindata) ); // finished.fi.PPThe QArray::setRawData() function is not for the inexperienced..SH "QDataStream::QDataStream ( QIODevice * d )"Constructs a data stream that uses the IO device \fId.\fR.PPSee also setDevice() and device()..SH "QDataStream::~QDataStream () \fC[virtual]\fR"Destructs the data stream..PPThe destructor will not affect the current IO device, unless it is an internal IO device processing a QByteArray passed in the constructor..SH "bool QDataStream::atEnd () const"Returns TRUE if the IO device has reached the end position (end of stream or file) or if there is no IO device set..PPReturns FALSE if the current position of the read/write head of the IO device is somewhere before the end position..PPSee also QIODevice::atEnd()..SH "int QDataStream::byteOrder () const"Returns the current byte order setting - either \fCBigEndian\fR or \fCLittleEndian.\fR.PPSee also setByteOrder()..SH "QIODevice * QDataStream::device () const"Returns the IO device currently set..PPSee also setDevice() and unsetDevice()..SH "bool QDataStream::eof () const"\fBThis function is obsolete.\fR It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code..PPReturns TRUE if the IO device has reached the end position (end of stream or file) or if there is no IO device set..PPReturns FALSE if the current position of the read/write head of the IO device is somewhere before the end position..PPSee also QIODevice::atEnd()..SH "bool QDataStream::isPrintableData () const"Returns TRUE if the printable data flag has been set..PPSee also setPrintableData()..SH "QDataStream & QDataStream::operator<< ( Q_INT16 i )"Writes a signed 16-bit integer to the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator<< ( Q_INT32 i )"Writes a signed 32-bit integer to the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator<< ( Q_INT64 i )"Writes a signed 64-bit integer to the stream and returns a reference to the stream, or calls the Q_INT32-operator if 64 bit is not available..SH "QDataStream & QDataStream::operator<< ( Q_INT8 i )"Writes a signed byte to the stream..SH "QDataStream & QDataStream::operator<< ( Q_UINT16 i )"Writes an unsigned 16-bit integer to the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator<< ( Q_UINT32 i )"Writes an unsigned 32-bit integer to the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator<< ( Q_UINT64 i )"Writes an unsigned 64-bit integer to the stream and returns a reference to the stream, or uses the Q_UINT32-operator if 64 bit is not available..SH "QDataStream & QDataStream::operator<< ( Q_UINT8 i )"Writes an unsigned byte to the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator<< ( const char * s )"Writes the '\\0'-terminated string \fIs\fR to the stream and returns a reference to the stream..PPThe string is serialized using writeBytes()..SH "QDataStream & QDataStream::operator<< ( double f )"Writes a 64-bit floating point number to the stream using the standard IEEE754 format. Returns a reference to the stream..SH "QDataStream & QDataStream::operator<< ( float f )"Writes a 32-bit floating point number to the stream using the standard IEEE754 format. Returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( Q_INT16 & i )"Reads a signed 16-bit integer from the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( Q_INT32 & i )"Reads a signed 32-bit integer from the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( Q_INT64 & i )"Reads a signed 64-bit integer from the stream and returns a reference to the stream, or uses the Q_UINT32 operator if 64 bit is not available..SH "QDataStream & QDataStream::operator>> ( Q_INT8 & i )"Reads a signed byte from the stream..SH "QDataStream & QDataStream::operator>> ( Q_UINT16 & i )"Reads an unsigned 16-bit integer from the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( Q_UINT32 & i )"Reads an unsigned 32-bit integer from the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( Q_UINT64 & i )"Reads an unsigned 64-bit integer from the stream and returns a reference to the stream, or uses the Q_UINT32 operator if 64 bit is not available..SH "QDataStream & QDataStream::operator>> ( Q_UINT8 & i )"Reads an unsigned byte from the stream and returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( char *& s )"Reads the '\\0'-terminated string \fIs\fR from the stream and returns a reference to the stream..PPSpace for the string is allocated using \fCnew\fR - the caller must eventually call delete[] on the value..SH "QDataStream & QDataStream::operator>> ( double & f )"Reads a 64-bit floating point number from the stream using the standard IEEE754 format. Returns a reference to the stream..SH "QDataStream & QDataStream::operator>> ( float & f )"Reads a 32-bit floating point number from the stream using the standard IEEE754 format. Returns a reference to the stream..SH "QDataStream & QDataStream::readBytes ( char *& s, uint & l )"Reads the buffer \fIs\fR from the stream and returns a reference to the stream..PPThe buffer \fIs\fR is allocated using \fCnew.\fR Destroy it with the \fCdelete[]\fR operator. If the length is zero or \fIs\fR cannot be allocated, \fIs\fR is set to 0..PPThe \fIl\fR parameter will be set to the length of the buffer..PPThe serialization format is an Q_UINT32 length specifier first, then the data (\fIl\fR bytes)..PPSee also readRawBytes() and writeBytes()..SH "QDataStream & QDataStream::readRawBytes ( char * s, uint len )"Reads \fIlen\fR bytes from the stream into \fIs\fR and returns a reference to the stream..PPThe buffer \fIs\fR must be preallocated..PPSee also readBytes(), QIODevice::readBlock() and writeRawBytes()..SH "void QDataStream::setByteOrder ( int bo )"Sets the serialization byte order to \fIbo.\fR.PPThe \fIbo\fR parameter can be \fCQDataStream::BigEndian\fR or \fCQDataStream::LittleEndian.\fR.PPThe default setting is big endian. We recommend leaving this setting unless you have special requirements..PPSee also byteOrder()..SH "void QDataStream::setDevice ( QIODevice * d )"void QDataStream::setDevice(QIODevice *d ) Sets the IO device to \fId.\fR.PPSee also device() and unsetDevice()..SH "void QDataStream::setPrintableData ( bool enable )"Sets or clears the printable data flag..PPIf this flag is set, the write functions will generate output that consists of printable characters (7 bit ASCII)..PPWe recommend enabling printable data only for debugging purposes (it is slower and creates larger output)..SH "void QDataStream::setVersion ( int v )"Sets the version number of the data serialization format..PPIn order to accomodate for 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 of QDataStream..PPFor Qt 1.x compatibility, use \fIv\fR == 1..PPFor Qt 2.0.x compatibility, use \fIv\fR == 2 (Not required for reading in Qt 2.1)..PPSee also version()..SH "void QDataStream::unsetDevice ()"Unsets the IO device. This is the same as calling setDevice( 0 )..PPSee also device() and setDevice()..SH "int QDataStream::version () const"Returns the version number of the data serialization format. In Qt 2.1, this number is by default 3..PPSee also setVersion()..SH "QDataStream & QDataStream::writeBytes ( const char * s, uint len )"Writes the length specifier \fIlen\fR and the buffer \fIs\fR to the stream and returns a reference to the stream..PPThe \fIlen\fR is serialized as an Q_UINT32, followed by \fIlen\fR bytes from \fIs.\fR.PPSee also writeRawBytes() and readBytes()..SH "QDataStream & QDataStream::writeRawBytes ( const char * s, uint len )"Writes \fIlen\fR bytes from \fIs\fR to the stream and returns a reference to the stream..PPSee also writeBytes(), QIODevice::writeBlock() and readRawBytes()..SH "SEE ALSO".BR http://doc.trolltech.com/qdatastream.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com. See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports make our job much simpler. Thank you..PIn case of content or formattting problems with this manual page, pleasereport them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qdatastream.3qt) and the Qtversion (2.3.10).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -