📄 qbytearray.3qt
字号:
'\" t.TH QByteArray 3qt "24 January 2005" "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 NAMEQByteArray \- Array of bytes.br.PP\fC#include <qcstring.h>\fR.PPInherits QArray..PPInherited by QBitArray and QCString..PP.SS "Public Members".in +1c.ti -1c.BI "\fBQByteArray\fR () ".br.ti -1c.BI "\fBQByteArray\fR ( int size ) ".br.ti -1c.BI "\fBQByteArray\fR ( const QByteArray & a ) ".br.ti -1c.BI "\fB~QByteArray\fR () ".br.ti -1c.BI "QByteArray& \fBoperator=\fR ( const QByteArray & a ) ".br.ti -1c.BI "char* \fBdata\fR () const".br.ti -1c.BI "uint \fBnrefs\fR () const".br.ti -1c.BI "uint \fBsize\fR () const".br.ti -1c.BI "uint \fBcount\fR () const".br.ti -1c.BI "bool \fBisEmpty\fR () const".br.ti -1c.BI "bool \fBisNull\fR () const".br.ti -1c.BI "bool \fBresize\fR ( uint size ) ".br.ti -1c.BI "bool \fBtruncate\fR ( uint pos ) ".br.ti -1c.BI "bool \fBfill\fR ( const char & " "d" ", int " "size" " = -1 ) ".br.ti -1c.BI "virtual void \fBdetach\fR () ".br.ti -1c.BI "QByteArray \fBcopy\fR () const".br.ti -1c.BI "QByteArray& \fBassign\fR ( const QByteArray & a ) ".br.ti -1c.BI "QByteArray& \fBassign\fR ( const char * " "a" ", uint n ) ".br.ti -1c.BI "QByteArray& \fBduplicate\fR ( const QByteArray & a ) ".br.ti -1c.BI "QByteArray& \fBduplicate\fR ( const char * " "a" ", uint n ) ".br.ti -1c.BI "QByteArray& \fBsetRawData\fR ( const char * " "a" ", uint n ) ".br.ti -1c.BI "void \fBresetRawData\fR ( const char * " "a" ", uint n ) ".br.ti -1c.BI "int \fBfind\fR ( const char & " "d" ", uint " "i" "=0 ) const".br.ti -1c.BI "int \fBcontains\fR ( const char & d ) const".br.ti -1c.BI "void \fBsort\fR () ".br.ti -1c.BI "int \fBbsearch\fR ( const char & d ) const".br.ti -1c.BI "char& \fBoperator[]\fR ( int i ) const".br.ti -1c.BI "char& \fBat\fR ( uint i ) const".br.ti -1c.BI "operator \fBconst char*\fR ()const".br.ti -1c.BI "bool \fBoperator==\fR ( const QByteArray & a ) const".br.ti -1c.BI "bool \fBoperator!=\fR ( const QByteArray & a ) const".br.ti -1c.BI "Iterator \fBbegin\fR () ".br.ti -1c.BI "Iterator \fBend\fR () ".br.ti -1c.BI "ConstIterator \fBbegin\fR () const".br.ti -1c.BI "ConstIterator \fBend\fR () const".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "\fBQByteArray\fR ( int, int ) ".br.in -1c.SH RELATED FUNCTION DOCUMENTATION(Note that these are not member functions.).in +1c.ti -1c.BI "QDataStream & \fBoperator>>\fR (QDataStream & " "s" ", QByteArray & " "a" ")".br.ti -1c.BI "QDataStream & \fBoperator<<\fR (QDataStream & " "s" ", const QByteArray & " "a" ")".br.ti -1c.BI "Q_UINT16 \fBqChecksum\fR (const char * " "data" ", uint " "len" ")".br.in -1c.SH DESCRIPTIONThe QByteArray class provides an array of bytes..PPThe QByteArray class provides an explicitly shared array of bytes. It is useful for manipulating memory areas with custom data. QByteArray is implemented as QArray<char>. See the QArray documentation for further information..SH MEMBER FUNCTION DOCUMENTATION.SH "QByteArray::QByteArray ()"Constructs a null array..PPSee also isNull()..SH "QByteArray::QByteArray ( const QByteArray & a )"Constructs a shallow copy of \fIa.\fR.PPSee also assign()..SH "QByteArray::QByteArray ( int size )"Constructs an array with room for \fIsize\fR elements. Makes a null array if \fIsize\fR == 0..PPNote that the elements are not initialized..PPSee also resize() and isNull()..SH "QByteArray::QByteArray ( int, int ) \fC[protected]\fR"Constructs an array \fIwithout allocating\fR array space. The arguments should be (0, 0). Use at own risk..SH "QByteArray::~QByteArray ()"Dereferences the array data and deletes it if this was the last reference..SH "QByteArray::operator const char * () const"Cast operator. Returns a pointer to the array..PPSee also data()..SH "QByteArray & QByteArray::assign ( const QByteArray & a )"Shallow copy. Dereferences the current array and references the data contained in \fIa\fR instead. Returns a reference to this array..PPSee also operator=()..SH "QByteArray & QByteArray::assign ( const char * data, uint size )"Shallow copy. Dereferences the current array and references the array data \fIdata,\fR which contains \fIsize\fR elements. Returns a reference to this array..PPDo not delete \fIdata\fR later, QArray takes care of that..SH "char & QByteArray::at ( uint index ) const"Returns a reference to the element at position \fIindex\fR in the array..PPThis can be used to both read and set an element..PPSee also operator[]()..SH "ConstIterator QByteArray::begin () const"Returns a const iterator pointing at the beginning of this array. This iterator can be used as the iterators of QValueList and QMap for example. In fact it does not only behave like a usual pointer: It is a pointer..SH "Iterator QByteArray::begin ()"Returns an iterator pointing at the beginning of this array. This iterator can be used as the iterators of QValueList and QMap for example. In fact it does not only behave like a usual pointer: It is a pointer..SH "int QByteArray::bsearch ( const char & v ) const"In a sorted array, finds the first occurrence of \fIv\fR using binary search. For a sorted array, this is generally much faster than find(), which does a linear search..PPReturns the position of \fIv,\fR or -1 if \fIv\fR could not be found..PPSee also sort() and find()..SH "int QByteArray::contains ( const char & v ) const"Returns the number of times \fIv\fR occurs in the array..PPSee also find()..SH "QByteArray QByteArray::copy () const"Returns a deep copy of this array..PPSee also detach() and duplicate()..SH "uint QByteArray::count () const"Returns the same as size()..PPSee also size()..SH "char * QByteArray::data () const"Returns a pointer to the actual array data..PPThe array is a null array if data() == 0 (null pointer)..PPSee also isNull()..SH "void QByteArray::detach () \fC[virtual]\fR"Detaches this array from shared array data, i.e. makes a private, deep copy of the data..PPCopying will only be performed if the reference count is greater than one..PPSee also copy()..PPReimplemented from QGArray..SH "QByteArray & QByteArray::duplicate ( const QByteArray & a )"Deep copy. Dereferences the current array and obtains a copy of the data contained in \fIa\fR instead. Returns a reference to this array..PPSee also copy()..SH "QByteArray & QByteArray::duplicate ( const char * data, uint size )"Deep copy. Dereferences the current array and obtains a copy of the array data \fIdata\fR instead. Returns a reference to this array..PPSee also copy()..SH "ConstIterator QByteArray::end () const"Returns a const iterator pointing behind the last element of this array. This iterator can be used as the iterators of QValueList and QMap for example. In fact it does not only behave like a usual pointer: It is a pointer..SH "Iterator QByteArray::end ()"Returns an iterator pointing behind the last element of this array. This iterator can be used as the iterators of QValueList and QMap for example. In fact it does not only behave like a usual pointer: It is a pointer..SH "bool QByteArray::fill ( const char & v, int size = -1 )"Fills the array with the value \fIv.\fR If \fIsize\fR is specified as different from -1, then the array will be resized before filled..PPReturns TRUE if successful, or FALSE if the memory cannot be allocated (only when \fIsize\fR != -1)..PPSee also resize()..SH "int QByteArray::find ( const char & v, uint index=0 ) const"Finds the first occurrence of \fIv,\fR starting at position \fIindex.\fR.PPReturns the position of \fIv,\fR or -1 if \fIv\fR could not be found..PPSee also contains()..SH "bool QByteArray::isEmpty () const"Returns TRUE if the array is empty, i.e. size() == 0, otherwise FALSE..PPisEmpty() is equivalent with isNull() for QArray. Note that this is not the case for QCString::isEmpty()..SH "bool QByteArray::isNull () const"Returns TRUE if the array is null, otherwise FALSE..PPA null array has size() == 0 and data() == 0..SH "uint QByteArray::nrefs () const"Returns the reference count for the shared array data. This reference count is always greater than zero..SH "bool QByteArray::operator!= ( const QByteArray & a ) const"Returns TRUE if this array is different from \fIa,\fR otherwise FALSE..PPThe two arrays are bitwise compared..PPSee also operator==()..SH "QByteArray & QByteArray::operator= ( const QByteArray & a )"Assigns a shallow copy of \fIa\fR to this array and returns a reference to this array..PPEquivalent to assign( a )..SH "bool QByteArray::operator== ( const QByteArray & a ) const"Returns TRUE if this array is equal to \fIa,\fR otherwise FALSE..PPThe two arrays are bitwise compared..PPSee also operator!=()..SH "char & QByteArray::operator[] ( int index ) const"Returns a reference to the element at position \fIindex\fR in the array..PPThis can be used to both read and set an element. Equivalent to at()..PPSee also at()..SH "void QByteArray::resetRawData ( const char * data, uint size )"Resets raw data that was set using setRawData()..PPThe arguments must be the data and length that were passed to setRawData(). This is for consistency checking..PPSee also setRawData()..SH "bool QByteArray::resize ( uint size )"Resizes (expands or shrinks) the array to \fIsize\fR elements. The array becomes a null array if \fIsize\fR == 0..PPReturns TRUE if successful, or FALSE if the memory cannot be allocated..PPNew elements will not be initialized..PPSee also size()..SH "QByteArray & QByteArray::setRawData ( const char * data, uint size )"Sets raw data and returns a reference to the array..PPDereferences the current array and sets the new array data to \fIdata\fR and the new array size to \fIsize.\fR Do not attempt to resize or re-assign the array data when raw data has been set. Call resetRawData(d,len) to reset the array..PPSetting raw data is useful because it sets QArray data without allocating memory or copying data..PPExample I (intended use):.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.PPExample II (you don't want to do this):.PP.nf.br static char bindata[] = { 231, 1, 44, ... };.br QByteArray a, b;.br a.setRawData( bindata, sizeof(bindata) ); // a points to bindata.br a.resize( 8 ); // will crash.br b = a; // will crash.br a[2] = 123; // might crash.br // forget to resetRawData - will crash.fi.PP\fBWarning:\fR If you do not call resetRawData(), QArray will attempt to deallocate or reallocate the raw data, which might not be too good. Be careful..PPSee also resetRawData()..SH "uint QByteArray::size () const"Returns the size of the array (max number of elements)..PPThe array is a null array if size() == 0..PPSee also isNull() and resize()..SH "void QByteArray::sort ()"Sorts the array elements in ascending order, using bitwise comparison (memcmp())..PPSee also bsearch()..SH "bool QByteArray::truncate ( uint pos )"Truncates the array at position \fIpos.\fR.PPReturns TRUE if successful, or FALSE if the memory cannot be allocated..PPEquivalent to resize(\fIpos).\fR.PPSee also resize()..SH RELATED FUNCTION DOCUMENTATION.SH "QDataStream & operator>> (QDataStream & s, QByteArray & a)"Reads a byte array from a stream and returns a reference to the stream..PPSee also Format of the QDataStream operators.SH "QDataStream & operator<< (QDataStream & s, const QByteArray & a)"Writes a byte array to a stream and returns a reference to the stream..PPSee also Format of the QDataStream operators.SH "Q_UINT16 qChecksum (const char * data, uint len)"Returns the CRC-16 checksum of \fIlen\fR bytes starting at \fIdata.\fR.PPThe checksum is independent of the byte order (endianness)..SH "SEE ALSO".BR http://doc.trolltech.com/qbytearray.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 (qbytearray.3qt) and the Qtversion (2.3.10).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -