⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qdatastream.3qt

📁 Linux下的基于X11的图形开发环境。
💻 3QT
📖 第 1 页 / 共 2 页
字号:
'\" t.TH QDataStream 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQDataStream \- Serialization of binary data to a QIODevice.SH SYNOPSISAll the functions in this class are reentrant when Qt is built with thread support.</p>.PP\fC#include <qdatastream.h>\fR.PP.SS "Public Members".in +1c.ti -1c.BI "\fBQDataStream\fR ()".br.ti -1c.BI "\fBQDataStream\fR ( QIODevice * d )".br.ti -1c.BI "\fBQDataStream\fR ( QByteArray a, int mode )".br.ti -1c.BI "virtual \fB~QDataStream\fR ()".br.ti -1c.BI "QIODevice * \fBdevice\fR () const".br.ti -1c.BI "void \fBsetDevice\fR ( QIODevice * d )".br.ti -1c.BI "void \fBunsetDevice\fR ()".br.ti -1c.BI "bool \fBatEnd\fR () const".br.ti -1c.BI "bool eof () const  \fI(obsolete)\fR".br.ti -1c.BI "enum \fBByteOrder\fR { BigEndian, LittleEndian }".br.ti -1c.BI "int \fBbyteOrder\fR () const".br.ti -1c.BI "void \fBsetByteOrder\fR ( int bo )".br.ti -1c.BI "bool \fBisPrintableData\fR () const".br.ti -1c.BI "void \fBsetPrintableData\fR ( bool enable )".br.ti -1c.BI "int \fBversion\fR () const".br.ti -1c.BI "void \fBsetVersion\fR ( int v )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_INT8 & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_UINT8 & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_INT16 & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_UINT16 & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_INT32 & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_UINT32 & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_LONG & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( Q_ULONG & i )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( float & f )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( double & f )".br.ti -1c.BI "QDataStream & \fBoperator>>\fR ( char *& s )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_INT8 i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_UINT8 i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_INT16 i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_UINT16 i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_INT32 i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_UINT32 i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_LONG i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( Q_ULONG i )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( float f )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( double f )".br.ti -1c.BI "QDataStream & \fBoperator<<\fR ( const char * s )".br.ti -1c.BI "QDataStream & \fBreadBytes\fR ( char *& s, uint & l )".br.ti -1c.BI "QDataStream & \fBreadRawBytes\fR ( char * s, uint len )".br.ti -1c.BI "QDataStream & \fBwriteBytes\fR ( const char * s, uint len )".br.ti -1c.BI "QDataStream & \fBwriteRawBytes\fR ( const char * s, uint len )".br.in -1c.SH DESCRIPTIONThe QDataStream class provides serialization of binary data to a QIODevice..PPA 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..PPYou can also use a data stream to read/write raw unencoded binary data. If you want a "parsing" input stream, see QTextStream..PPThe QDataStream class implements serialization of primitive types, like \fCchar\fR, \fCshort\fR, \fCint\fR, \fCchar*\fR etc. Serialization of more complex data is accomplished by breaking up the data into primitive units..PPA data stream cooperates closely with a QIODevice. A QIODevice represents an input/output medium one can read data from and write data to. The QFile class is an example of an IO device..PPExample (write binary data to a stream):.PP.nf.br    QFile file( "file.dat" );.br    file.open( IO_WriteOnly );.br    QDataStream stream( &file ); // we will serialize the data into the file.br    stream << "the answer is";   // serialize a string.br    stream << (Q_INT32)42;       // serialize an integer.br.fi.PPExample (read binary data from a stream):.PP.nf.br    QFile file( "file.dat" );.br    file.open( IO_ReadOnly );.br    QDataStream stream( &file );  // read the data serialized from the file.br    QString str;.br    Q_INT32 a;.br    stream >> str >> a;           // extract "the answer is" and 42.br.fi.PPEach item written to the stream is written in a predefined binary format that varies depending on the item's type. Supported Qt types include QBrush, QColor, QDateTime, QFont, QPixmap, QString, QVariant and many others. For the complete list of all Qt types supporting data streaming see the Format of the QDataStream operators..PPTo take one example, a \fCchar*\fR string is written as a 32-bit integer equal to the length of the string including the NUL byte ('&#92;0'), followed by all the characters of the string including the NUL byte. When reading a \fCchar*\fR string, 4 bytes are read to create the 32-bit length value, then that many characters for the \fCchar*\fR string including the NUL are read..PPThe initial IODevice is usually set in the constructor, but can be changed with setDevice(). If you've reached the end of the data (or if there is no IODevice set) atEnd() will return TRUE..PPIf you want the data to be compatible with an earlier version of Qt use setVersion()..PPIf you want the data to be human-readable, e.g. for debugging, you can set the data stream into printable data mode with setPrintableData(). The data is then written slower, in a bloated but human readable format..PPIf 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:.PP.nf.br    QFile file( "file.xxx" );.br    file.open( IO_WriteOnly );.br    QDataStream stream( &file );.br.br    // Write a header with a "magic number" and a version.br    stream << (Q_UINT32)0xA0B0C0D0;.br    stream << (Q_INT32)123;.br.br    // Write the data.br    stream << [lots of interesting data].br.fi.PPThen read it in with:.PP.nf.br    QFile file( "file.xxx" );.br    file.open( IO_ReadOnly );.br    QDataStream stream( &file );.br.br    // Read and check the header.br    Q_UINT32 magic;.br    stream >> magic;.br    if ( magic != 0xA0B0C0D0 ).br        return XXX_BAD_FILE_FORMAT;.br.br    // Read the version.br    Q_INT32 version;.br    stream >> 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        stream.setVersion(1);.br.br    // Read the data.br    stream >> [lots of interesting data];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -