7
7
tr.address { font-family: sans-serif }
8
8
body { background: #ffffff; color: black; }
9
9
</style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr /><td align="left" valign="top" width="32"><img align="left" border="0" height="32" src="images/rb-logo.png" width="32" /></td><td width="1">  </td><td class="postheader" valign="center"><a href="../pyqt4ref.html"><font color="#004faf">Home</font></a> · <a href="classes.html"><font color="#004faf">All Classes</font></a> · <a href="modules.html"><font color="#004faf">Modules</font></a></td></table><h1 align="center">QByteArray Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QByteArray class provides an array of bytes. <a href="#details">More...</a></p>
10
11
<h3>Methods</h3><ul><li><div class="fn" /><b><a href="qbytearray.html#QByteArray">__init__</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qbytearray.html#QByteArray-2">__init__</a></b> (<i>self</i>, int, str)</li><li><div class="fn" /><b><a href="qbytearray.html#QByteArray-3">__init__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#append">append</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#append-2">append</a></b> (<i>self</i>, QString)</li><li><div class="fn" />str <b><a href="qbytearray.html#at">at</a></b> (<i>self</i>, int)</li><li><div class="fn" />int <b><a href="qbytearray.html#capacity">capacity</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qbytearray.html#chop">chop</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qbytearray.html#clear">clear</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#contains">contains</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />int <b><a href="qbytearray.html#count">count</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />int <b><a href="qbytearray.html#count-2">count</a></b> (<i>self</i>)</li><li><div class="fn" />str <b><a href="qbytearray.html#data">data</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#endsWith">endsWith</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#fill">fill</a></b> (<i>self</i>, str, int <i>size</i> = -1)</li><li><div class="fn" />int <b><a href="qbytearray.html#indexOf">indexOf</a></b> (<i>self</i>, QByteArray, int <i>from</i> = 0)</li><li><div class="fn" />int <b><a href="qbytearray.html#indexOf-2">indexOf</a></b> (<i>self</i>, QString, int <i>from</i> = 0)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#insert">insert</a></b> (<i>self</i>, int, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#insert-2">insert</a></b> (<i>self</i>, int, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#isEmpty">isEmpty</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#isNull">isNull</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qbytearray.html#lastIndexOf">lastIndexOf</a></b> (<i>self</i>, QByteArray, int <i>from</i> = -1)</li><li><div class="fn" />int <b><a href="qbytearray.html#lastIndexOf-2">lastIndexOf</a></b> (<i>self</i>, QString, int <i>from</i> = -1)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#left">left</a></b> (<i>self</i>, int)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#leftJustified">leftJustified</a></b> (<i>self</i>, int, str <i>fill</i> = ' ', bool <i>truncate</i> = False)</li><li><div class="fn" />int <b><a href="qbytearray.html#length">length</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#mid">mid</a></b> (<i>self</i>, int, int <i>length</i> = -1)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#prepend">prepend</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" /><b><a href="qbytearray.html#push_back">push_back</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" /><b><a href="qbytearray.html#push_front">push_front</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#remove">remove</a></b> (<i>self</i>, int, int)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#repeated">repeated</a></b> (<i>self</i>, int)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#replace">replace</a></b> (<i>self</i>, int, int, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#replace-2">replace</a></b> (<i>self</i>, QByteArray, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#replace-3">replace</a></b> (<i>self</i>, QString, QByteArray)</li><li><div class="fn" /><b><a href="qbytearray.html#reserve">reserve</a></b> (<i>self</i>, int)</li><li><div class="fn" /><b><a href="qbytearray.html#resize">resize</a></b> (<i>self</i>, int)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#right">right</a></b> (<i>self</i>, int)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#rightJustified">rightJustified</a></b> (<i>self</i>, int, str <i>fill</i> = ' ', bool <i>truncate</i> = False)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#setNum">setNum</a></b> (<i>self</i>, int, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#setNum-2">setNum</a></b> (<i>self</i>, float, str <i>format</i> = 'g', int <i>precision</i> = 6)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#setNum-3">setNum</a></b> (<i>self</i>, int, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#setNum-4">setNum</a></b> (<i>self</i>, int, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#simplified">simplified</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qbytearray.html#size">size</a></b> (<i>self</i>)</li><li><div class="fn" />list-of-QByteArray <b><a href="qbytearray.html#split">split</a></b> (<i>self</i>, str)</li><li><div class="fn" /><b><a href="qbytearray.html#squeeze">squeeze</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#startsWith">startsWith</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#toBase64">toBase64</a></b> (<i>self</i>)</li><li><div class="fn" />(float, bool <i>ok</i>) <b><a href="qbytearray.html#toDouble">toDouble</a></b> (<i>self</i>)</li><li><div class="fn" />(float, bool <i>ok</i>) <b><a href="qbytearray.html#toFloat">toFloat</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#toHex">toHex</a></b> (<i>self</i>)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toInt">toInt</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toLong">toLong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toLongLong">toLongLong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#toLower">toLower</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#toPercentEncoding">toPercentEncoding</a></b> (<i>self</i>, QByteArray <i>exclude</i> = QByteArray(), QByteArray <i>include</i> = QByteArray(), str <i>percent</i> = '%')</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toShort">toShort</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toUInt">toUInt</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toULong">toULong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toULongLong">toULongLong</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#toUpper">toUpper</a></b> (<i>self</i>)</li><li><div class="fn" />(int, bool <i>ok</i>) <b><a href="qbytearray.html#toUShort">toUShort</a></b> (<i>self</i>, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#trimmed">trimmed</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qbytearray.html#truncate">truncate</a></b> (<i>self</i>, int)</li></ul><h3>Static Methods</h3><ul><li><div class="fn" />QByteArray <b><a href="qbytearray.html#fromBase64">fromBase64</a></b> (QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#fromHex">fromHex</a></b> (QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#fromPercentEncoding">fromPercentEncoding</a></b> (QByteArray, str <i>percent</i> = '%')</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#fromRawData">fromRawData</a></b> (str)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#number">number</a></b> (int, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#number-2">number</a></b> (float, str <i>format</i> = 'g', int <i>precision</i> = 6)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#number-3">number</a></b> (int, int <i>base</i> = 10)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#number-4">number</a></b> (int, int <i>base</i> = 10)</li></ul><h3>Special Methods</h3><ul><li><div class="fn" />QByteArray <b><a href="qbytearray.html#__add__">__add__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QString <b><a href="qbytearray.html#__add__-2">__add__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />int <b><a href="qbytearray.html#__contains__">__contains__</a></b> (<i>self</i>, QByteArray <i>a</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__eq__">__eq__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__eq__-2">__eq__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__ge__">__ge__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__ge__-2">__ge__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />str <b><a href="qbytearray.html#__getitem__">__getitem__</a></b> (<i>self</i>, int)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#__getitem__-2">__getitem__</a></b> (<i>self</i>, slice <i>slice</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__gt__">__gt__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__gt__-2">__gt__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />int <b><a href="qbytearray.html#__hash__">__hash__</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#__iadd__">__iadd__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#__iadd__-2">__iadd__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#__imul__">__imul__</a></b> (<i>self</i>, int <i>m</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__le__">__le__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__le__-2">__le__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" /> <b><a href="qbytearray.html#__len__">__len__</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__lt__">__lt__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__lt__-2">__lt__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />QByteArray <b><a href="qbytearray.html#__mul__">__mul__</a></b> (<i>self</i>, int <i>m</i>)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__ne__">__ne__</a></b> (<i>self</i>, QString)</li><li><div class="fn" />bool <b><a href="qbytearray.html#__ne__-2">__ne__</a></b> (<i>self</i>, QByteArray)</li><li><div class="fn" />str <b><a href="qbytearray.html#__repr__">__repr__</a></b> (<i>self</i>)</li><li><div class="fn" />str <b><a href="qbytearray.html#__str__">__str__</a></b> (<i>self</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>This class can be pickled.</p><p>A Python string object
11
12
may be used whenever a
12
13
<a href="qbytearray.html">QByteArray</a>
14
15
<p>The QByteArray class provides an array of bytes.</p>
15
<p>QByteArray can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings. Using QByteArray is much more convenient than using <tt>const char *</tt>. Behind the scenes, it always ensures that the data is followed by a '\0' terminator, and uses <a href="implicit-sharing.html">implicit sharing</a> (copy-on-write) to reduce memory usage and avoid needless copying of data.</p>
16
<p>In addition to QByteArray, Qt also provides the <a href="qstring.html">QString</a> class to store string data. For most purposes, <a href="qstring.html">QString</a> is the class you want to use. It stores 16-bit Unicode characters, making it easy to store non-ASCII/non-Latin-1 characters in your application. Furthermore, <a href="qstring.html">QString</a> is used throughout in the Qt API. The two main cases where QByteArray is appropriate are when you need to store raw binary data, and when memory conservation is critical (e.g., with Qt for Embedded Linux).</p>
17
<p>One way to initialize a QByteArray is simply to pass a <tt>const char *</tt> to its constructor. For example, the following code creates a byte array of size 5 containing the data "Hello":</p>
18
<pre> QByteArray ba("Hello");</pre>
19
<p>Although the <a href="qbytearray.html#size">size</a>() is 5, the byte array also maintains an extra '\0' character at the end so that if a function is used that asks for a pointer to the underlying data (e.g. a call to <a href="qbytearray.html#data">data</a>()), the data pointed to is guaranteed to be '\0'-terminated.</p>
20
<p>QByteArray makes a deep copy of the <tt>const char *</tt> data, so you can modify it later without experiencing side effects. (If for performance reasons you don't want to take a deep copy of the character data, use <a href="qbytearray.html#fromRawData">QByteArray.fromRawData</a>() instead.)</p>
21
<p>Another approach is to set the size of the array using <a href="qbytearray.html#resize">resize</a>() and to initialize the data byte per byte. QByteArray uses 0-based indexes, just like C++ arrays. To access the byte at a particular index position, you can use operator[](). On non-const byte arrays, operator[]() returns a reference to a byte that can be used on the left side of an assignment. For example:</p>
16
<p>QByteArray can be used to store both raw bytes (including '\0's)
17
and traditional 8-bit '\0'-terminated strings. Using QByteArray is
18
much more convenient than using <tt>const char *</tt>. Behind the
19
scenes, it always ensures that the data is followed by a '\0'
20
terminator, and uses <a href="implicit-sharing.html">implicit
21
sharing</a> (copy-on-write) to reduce memory usage and avoid
22
needless copying of data.</p>
23
<p>In addition to QByteArray, Qt also provides the <a href="qstring.html">QString</a> class to store string data. For most
24
purposes, <a href="qstring.html">QString</a> is the class you want
25
to use. It stores 16-bit Unicode characters, making it easy to
26
store non-ASCII/non-Latin-1 characters in your application.
27
Furthermore, <a href="qstring.html">QString</a> is used throughout
28
in the Qt API. The two main cases where QByteArray is appropriate
29
are when you need to store raw binary data, and when memory
30
conservation is critical (e.g., with Qt for Embedded Linux).</p>
31
<p>One way to initialize a QByteArray is simply to pass a <tt>const
32
char *</tt> to its constructor. For example, the following code
33
creates a byte array of size 5 containing the data "Hello":</p>
34
<pre class="highlightedCode brush: cpp">
35
QByteArray ba("Hello");
37
<p>Although the <a href="qbytearray.html#size">size</a>() is 5, the
38
byte array also maintains an extra '\0' character at the end so
39
that if a function is used that asks for a pointer to the
40
underlying data (e.g. a call to <a href="qbytearray.html#data">data</a>()), the data pointed to is
41
guaranteed to be '\0'-terminated.</p>
42
<p>QByteArray makes a deep copy of the <tt>const char *</tt> data,
43
so you can modify it later without experiencing side effects. (If
44
for performance reasons you don't want to take a deep copy of the
45
character data, use <a href="qbytearray.html#fromRawData">QByteArray.fromRawData</a>()
47
<p>Another approach is to set the size of the array using <a href="qbytearray.html#resize">resize</a>() and to initialize the data
48
byte per byte. QByteArray uses 0-based indexes, just like C++
49
arrays. To access the byte at a particular index position, you can
50
use operator[](). On non-const byte arrays, operator[]() returns a
51
reference to a byte that can be used on the left side of an
52
assignment. For example:</p>
53
<pre class="highlightedCode brush: cpp">
29
62
<p>For read-only access, an alternative syntax is to use <a href="qbytearray.html#at">at</a>():</p>
30
<pre> for (int i = 0; i < ba.size(); ++i) {
63
<pre class="highlightedCode brush: cpp">
64
for (int i = 0; i < ba.size(); ++i) {
31
65
if (ba.at(i) >= 'a' && ba.at(i) <= 'f')
32
66
cout << "Found character in range [a-f]" << endl;
34
<p><a href="qbytearray.html#at">at</a>() can be faster than operator[](), because it never causes a <a href="implicit-sharing.html#deep-copy">deep copy</a> to occur.</p>
69
<p><a href="qbytearray.html#at">at</a>() can be faster than
70
operator[](), because it never causes a <a href="implicit-sharing.html#deep-copy">deep copy</a> to occur.</p>
35
71
<p>To extract many bytes at a time, use <a href="qbytearray.html#left">left</a>(), <a href="qbytearray.html#right">right</a>(), or <a href="qbytearray.html#mid">mid</a>().</p>
36
<p>A QByteArray can embed '\0' bytes. The <a href="qbytearray.html#size">size</a>() function always returns the size of the whole array, including embedded '\0' bytes. If you want to obtain the length of the data up to and excluding the first '\0' character, call <a href="qtcore.html#qstrlen">qstrlen</a>() on the byte array.</p>
37
<p>After a call to <a href="qbytearray.html#resize">resize</a>(), newly allocated bytes have undefined values. To set all the bytes to a particular value, call <a href="qbytearray.html#fill">fill</a>().</p>
38
<p>To obtain a pointer to the actual character data, call <a href="qbytearray.html#data">data</a>() or <a href="qbytearray.html#constData">constData</a>(). These functions return a pointer to the beginning of the data. The pointer is guaranteed to remain valid until a non-const function is called on the QByteArray. It is also guaranteed that the data ends with a '\0' byte. This '\0' byte is automatically provided by QByteArray and is not counted in <a href="qbytearray.html#size">size</a>().</p>
39
<p>QByteArray provides the following basic functions for modifying the byte data: <a href="qbytearray.html#append">append</a>(), <a href="qbytearray.html#prepend">prepend</a>(), <a href="qbytearray.html#insert">insert</a>(), <a href="qbytearray.html#replace">replace</a>(), and <a href="qbytearray.html#remove">remove</a>(). For example:</p>
40
<pre> QByteArray x("and");
72
<p>A QByteArray can embed '\0' bytes. The <a href="qbytearray.html#size">size</a>() function always returns the size
73
of the whole array, including embedded '\0' bytes. If you want to
74
obtain the length of the data up to and excluding the first '\0'
75
character, call <a href="qtcore.html#qstrlen">qstrlen</a>() on
77
<p>After a call to <a href="qbytearray.html#resize">resize</a>(),
78
newly allocated bytes have undefined values. To set all the bytes
79
to a particular value, call <a href="qbytearray.html#fill">fill</a>().</p>
80
<p>To obtain a pointer to the actual character data, call <a href="qbytearray.html#data">data</a>() or <a href="qbytearray.html#constData">constData</a>(). These functions return
81
a pointer to the beginning of the data. The pointer is guaranteed
82
to remain valid until a non-const function is called on the
83
QByteArray. It is also guaranteed that the data ends with a '\0'
84
byte. This '\0' byte is automatically provided by QByteArray and is
85
not counted in <a href="qbytearray.html#size">size</a>().</p>
86
<p>QByteArray provides the following basic functions for modifying
87
the byte data: <a href="qbytearray.html#append">append</a>(),
88
<a href="qbytearray.html#prepend">prepend</a>(), <a href="qbytearray.html#insert">insert</a>(), <a href="qbytearray.html#replace">replace</a>(), and <a href="qbytearray.html#remove">remove</a>(). For example:</p>
89
<pre class="highlightedCode brush: cpp">
41
91
x.prepend("rock "); <span class="comment">// x == "rock and"</span>
42
92
x.append(" roll"); <span class="comment">// x == "rock and roll"</span>
43
x.replace(5, 3, "&"); <span class="comment">// x == "rock & roll"</span></pre>
44
<p>The <a href="qbytearray.html#replace">replace</a>() and <a href="qbytearray.html#remove">remove</a>() functions' first two arguments are the position from which to start erasing and the number of bytes that should be erased.</p>
45
<p>When you <a href="qbytearray.html#append">append</a>() data to a non-empty array, the array will be reallocated and the new data copied to it. You can avoid this behavior by calling <a href="qbytearray.html#reserve">reserve</a>(), which preallocates a certain amount of memory. You can also call <a href="qbytearray.html#capacity">capacity</a>() to find out how much memory QByteArray actually allocated. Data appended to an empty array is not copied.</p>
46
<p>A frequent requirement is to remove whitespace characters from a byte array ('\n', '\t', ' ', etc.). If you want to remove whitespace from both ends of a QByteArray, use <a href="qbytearray.html#trimmed">trimmed</a>(). If you want to remove whitespace from both ends and replace multiple consecutive whitespaces with a single space character within the byte array, use <a href="qbytearray.html#simplified">simplified</a>().</p>
47
<p>If you want to find all occurrences of a particular character or substring in a QByteArray, use <a href="qbytearray.html#indexOf">indexOf</a>() or <a href="qbytearray.html#lastIndexOf">lastIndexOf</a>(). The former searches forward starting from a given index position, the latter searches backward. Both return the index position of the character or substring if they find it; otherwise, they return -1. For example, here's a typical loop that finds all occurrences of a particular substring:</p>
48
<pre> QByteArray ba("We must be <b>bold</b>, very <b>bold</b>");
93
x.replace(5, 3, "&"); <span class="comment">// x == "rock & roll"</span>
95
<p>The <a href="qbytearray.html#replace">replace</a>() and <a href="qbytearray.html#remove">remove</a>() functions' first two
96
arguments are the position from which to start erasing and the
97
number of bytes that should be erased.</p>
98
<p>When you <a href="qbytearray.html#append">append</a>() data to a
99
non-empty array, the array will be reallocated and the new data
100
copied to it. You can avoid this behavior by calling <a href="qbytearray.html#reserve">reserve</a>(), which preallocates a
101
certain amount of memory. You can also call <a href="qbytearray.html#capacity">capacity</a>() to find out how much
102
memory QByteArray actually allocated. Data appended to an empty
103
array is not copied.</p>
104
<p>A frequent requirement is to remove whitespace characters from a
105
byte array ('\n', '\t', ' ', etc.). If you want to remove
106
whitespace from both ends of a QByteArray, use <a href="qbytearray.html#trimmed">trimmed</a>(). If you want to remove
107
whitespace from both ends and replace multiple consecutive
108
whitespaces with a single space character within the byte array,
109
use <a href="qbytearray.html#simplified">simplified</a>().</p>
110
<p>If you want to find all occurrences of a particular character or
111
substring in a QByteArray, use <a href="qbytearray.html#indexOf">indexOf</a>() or <a href="qbytearray.html#lastIndexOf">lastIndexOf</a>(). The former
112
searches forward starting from a given index position, the latter
113
searches backward. Both return the index position of the character
114
or substring if they find it; otherwise, they return -1. For
115
example, here's a typical loop that finds all occurrences of a
116
particular substring:</p>
117
<pre class="highlightedCode brush: cpp">
118
QByteArray ba("We must be <b>bold</b>, very <b>bold</b>");
50
120
while ((j = ba.indexOf("<b>", j)) != -1) {
51
121
cout << "Found <b> tag at index position " << j << endl;
54
<p>If you simply want to check whether a QByteArray contains a particular character or substring, use <a href="qbytearray.html#contains">contains</a>(). If you want to find out how many times a particular character or substring occurs in the byte array, use <a href="qbytearray.html#count">count</a>(). If you want to replace all occurrences of a particular value with another, use one of the two-parameter <a href="qbytearray.html#replace">replace</a>() overloads.</p>
55
<p>QByteArrays can be compared using overloaded operators such as operator<(), operator<=(), operator==(), operator>=(), and so on. The comparison is based exclusively on the numeric values of the characters and is very fast, but is not what a human would expect. <a href="qstring.html#localeAwareCompare">QString.localeAwareCompare</a>() is a better choice for sorting user-interface strings.</p>
56
<p>For historical reasons, QByteArray distinguishes between a null byte array and an empty byte array. A <i>null</i> byte array is a byte array that is initialized using QByteArray's default constructor or by passing (const char *)0 to the constructor. An <i>empty</i> byte array is any byte array with size 0. A null byte array is always empty, but an empty byte array isn't necessarily null:</p>
57
<pre> QByteArray().isNull(); <span class="comment">// returns true</span>
125
<p>If you simply want to check whether a QByteArray contains a
126
particular character or substring, use <a href="qbytearray.html#contains">contains</a>(). If you want to find out
127
how many times a particular character or substring occurs in the
128
byte array, use <a href="qbytearray.html#count">count</a>(). If you
129
want to replace all occurrences of a particular value with another,
130
use one of the two-parameter <a href="qbytearray.html#replace">replace</a>() overloads.</p>
131
<p>QByteArrays can be compared using overloaded operators such as
132
operator<(), operator<=(), operator==(), operator>=(), and
133
so on. The comparison is based exclusively on the numeric values of
134
the characters and is very fast, but is not what a human would
135
expect. <a href="qstring.html#localeAwareCompare">QString.localeAwareCompare</a>()
136
is a better choice for sorting user-interface strings.</p>
137
<p>For historical reasons, QByteArray distinguishes between a null
138
byte array and an empty byte array. A <i>null</i> byte array is a
139
byte array that is initialized using QByteArray's default
140
constructor or by passing (const char *)0 to the constructor. An
141
<i>empty</i> byte array is any byte array with size 0. A null byte
142
array is always empty, but an empty byte array isn't necessarily
144
<pre class="highlightedCode brush: cpp">
145
QByteArray().isNull(); <span class="comment">// returns true</span>
58
146
QByteArray().isEmpty(); <span class="comment">// returns true</span>
60
148
QByteArray("").isNull(); <span class="comment">// returns false</span>
61
149
QByteArray("").isEmpty(); <span class="comment">// returns true</span>
63
151
QByteArray("abc").isNull(); <span class="comment">// returns false</span>
64
QByteArray("abc").isEmpty(); <span class="comment">// returns false</span></pre>
65
<p>All functions except <a href="qbytearray.html#isNull">isNull</a>() treat null byte arrays the same as empty byte arrays. For example, <a href="qbytearray.html#data">data</a>() returns a pointer to a '\0' character for a null byte array (<i>not</i> a null pointer), and <a href="qbytearray.html#QByteArray">QByteArray</a>() compares equal to QByteArray(""). We recommend that you always use <a href="qbytearray.html#isEmpty">isEmpty</a>() and avoid <a href="qbytearray.html#isNull">isNull</a>().</p>
66
<a name="notes-on-locale" />
152
QByteArray("abc").isEmpty(); <span class="comment">// returns false</span>
154
<p>All functions except <a href="qbytearray.html#isNull">isNull</a>() treat null byte arrays the
155
same as empty byte arrays. For example, <a href="qbytearray.html#data">data</a>() returns a pointer to a '\0'
156
character for a null byte array (<i>not</i> a null pointer), and
157
<a href="qbytearray.html#QByteArray">QByteArray</a>() compares
158
equal to QByteArray(""). We recommend that you always use <a href="qbytearray.html#isEmpty">isEmpty</a>() and avoid <a href="qbytearray.html#isNull">isNull</a>().</p>
159
<a id="notes-on-locale" name="notes-on-locale" />
67
160
<h3>Notes on Locale</h3>
68
<a name="number-string-conversions" />
161
<a id="number-string-conversions" name="number-string-conversions" />
69
162
<h4>Number-String Conversions</h4>
70
<p>Functions that perform conversions between numeric data types and strings are performed in the C locale, irrespective of the user's locale settings. Use <a href="qstring.html">QString</a> to perform locale-aware conversions between numbers and strings.</p>
163
<p>Functions that perform conversions between numeric data types
164
and strings are performed in the C locale, irrespective of the
165
user's locale settings. Use <a href="qstring.html">QString</a> to
166
perform locale-aware conversions between numbers and strings.</p>
71
167
<a name="8-bit-character-comparisons" />
72
168
<h4>8-bit Character Comparisons</h4>
73
<p>In QByteArray, the notion of uppercase and lowercase and of which character is greater than or less than another character is locale dependent. This affects functions that support a case insensitive option or that compare or lowercase or uppercase their arguments. Case insensitive operations and comparisons will be accurate if both strings contain only ASCII characters. (If <tt>$LC_CTYPE</tt> is set, most Unix systems do "the right thing".) Functions that this affects include <a href="qbytearray.html#contains">contains</a>(), <a href="qbytearray.html#indexOf">indexOf</a>(), <a href="qbytearray.html#lastIndexOf">lastIndexOf</a>(), operator<(), operator<=(), operator>(), operator>=(), <a href="qbytearray.html#toLower">toLower</a>() and <a href="qbytearray.html#toUpper">toUpper</a>().</p>
74
<p>This issue does not apply to QStrings since they represent characters using Unicode.</p>
75
<p>See also <a href="qstring.html">QString</a> and <a href="qbitarray.html">QBitArray</a>.</p>
169
<p>In QByteArray, the notion of uppercase and lowercase and of
170
which character is greater than or less than another character is
171
locale dependent. This affects functions that support a case
172
insensitive option or that compare or lowercase or uppercase their
173
arguments. Case insensitive operations and comparisons will be
174
accurate if both strings contain only ASCII characters. (If
175
<tt>$LC_CTYPE</tt> is set, most Unix systems do "the right thing".)
176
Functions that this affects include <a href="qbytearray.html#contains">contains</a>(), <a href="qbytearray.html#indexOf">indexOf</a>(), <a href="qbytearray.html#lastIndexOf">lastIndexOf</a>(), operator<(),
177
operator<=(), operator>(), operator>=(), <a href="qbytearray.html#toLower">toLower</a>() and <a href="qbytearray.html#toUpper">toUpper</a>().</p>
178
<p>This issue does not apply to QStrings since they represent
179
characters using Unicode.</p>
76
180
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QByteArray" />QByteArray.__init__ (<i>self</i>)</h3><p>Constructs an empty byte array.</p>
77
181
<p>See also <a href="qbytearray.html#isEmpty">isEmpty</a>().</p>
78
<h3 class="fn"><a name="QByteArray-2" />QByteArray.__init__ (<i>self</i>, int, str)</h3><p>Constructs a byte array initialized with the string <i>str</i>.</p>
79
<p><a href="qbytearray.html">QByteArray</a> makes a deep copy of the string data.</p>
80
<h3 class="fn"><a name="QByteArray-3" />QByteArray.__init__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Constructs a byte array containing the first <i>size</i> bytes of array <i>data</i>.</p>
184
<h3 class="fn"><a name="QByteArray-2" />QByteArray.__init__ (<i>self</i>, int, str)</h3><p>Constructs a byte array initialized with the string
186
<p><a href="qbytearray.html">QByteArray</a> makes a deep copy of
190
<h3 class="fn"><a name="QByteArray-3" />QByteArray.__init__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Constructs a byte array containing the first <i>size</i> bytes
191
of array <i>data</i>.</p>
81
192
<p>If <i>data</i> is 0, a null byte array is constructed.</p>
82
<p><a href="qbytearray.html">QByteArray</a> makes a deep copy of the string data.</p>
193
<p><a href="qbytearray.html">QByteArray</a> makes a deep copy of
83
195
<p>See also <a href="qbytearray.html#fromRawData">fromRawData</a>().</p>
84
<h3 class="fn"><a name="append" /><a href="qbytearray.html">QByteArray</a> QByteArray.append (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Appends the byte array <i>ba</i> onto the end of this byte array.</p>
198
<h3 class="fn"><a name="append" /><a href="qbytearray.html">QByteArray</a> QByteArray.append (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Appends the byte array <i>ba</i> onto the end of this byte
86
<pre> QByteArray x("free");
201
<pre class="highlightedCode brush: cpp">
202
QByteArray x("free");
87
203
QByteArray y("dom");
89
<span class="comment"> // x == "freedom"</span></pre>
205
<span class="comment"> // x == "freedom"</span>
90
207
<p>This is the same as insert(<a href="qbytearray.html#size">size</a>(), <i>ba</i>).</p>
91
<p>This operation is typically very fast (<a href="containers.html#constant-time">constant time</a>), because <a href="qbytearray.html">QByteArray</a> preallocates extra space at the end of the character data so it can grow without reallocating the entire data each time.</p>
92
<p>Note: <a href="qbytearray.html">QByteArray</a> is an <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a> class. Consequently, if <i>this</i> is an empty <a href="qbytearray.html">QByteArray</a>, then <i>this</i> will just share the data held in <i>ba</i>. In this case, no copying of data is done.</p>
208
<p>This operation is typically very fast (<a href="containers.html#constant-time">constant time</a>), because
209
<a href="qbytearray.html">QByteArray</a> preallocates extra space
210
at the end of the character data so it can grow without
211
reallocating the entire data each time.</p>
212
<p>Note: <a href="qbytearray.html">QByteArray</a> is an <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a>
213
class. Consequently, if <i>this</i> is an empty <a href="qbytearray.html">QByteArray</a>, then <i>this</i> will just share
214
the data held in <i>ba</i>. In this case, no copying of data is
93
216
<p>See also <a href="qbytearray.html#operator-2b-eq">operator+=</a>(), <a href="qbytearray.html#prepend">prepend</a>(), and <a href="qbytearray.html#insert">insert</a>().</p>
94
219
<h3 class="fn"><a name="append-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.append (<i>self</i>, QString)</h3><p>This is an overloaded function.</p>
95
<p>Appends the string <i>str</i> to this byte array. The Unicode data is converted into 8-bit characters using <a href="qstring.html#toAscii">QString.toAscii</a>().</p>
96
<p>If the <a href="qstring.html">QString</a> contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining <tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications. You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly if you want to convert the data to <tt>const char *</tt>.</p>
97
<h3 class="fn"><a name="at" />str QByteArray.at (<i>self</i>, int)</h3><p>Returns the character at index position <i>i</i> in the byte array.</p>
98
<p><i>i</i> must be a valid index position in the byte array (i.e., 0 <= <i>i</i> < <a href="qbytearray.html#size">size</a>()).</p>
220
<p>Appends the string <i>str</i> to this byte array. The Unicode
221
data is converted into 8-bit characters using <a href="qstring.html#toAscii">QString.toAscii</a>().</p>
222
<p>If the <a href="qstring.html">QString</a> contains non-ASCII
223
Unicode characters, using this function can lead to loss of
224
information. You can disable this function by defining
225
<tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications.
226
You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly
227
if you want to convert the data to <tt>const char *</tt>.</p>
230
<h3 class="fn"><a name="at" />str QByteArray.at (<i>self</i>, int)</h3><p>Returns the character at index position <i>i</i> in the byte
232
<p><i>i</i> must be a valid index position in the byte array (i.e.,
233
0 <= <i>i</i> < <a href="qbytearray.html#size">size</a>()).</p>
99
234
<p>See also <a href="qbytearray.html#operator-5b-5d">operator[]</a>().</p>
100
<a name="//apple_ref/cpp/instm/QByteArray/capacity" />
101
<h3 class="fn"><a name="capacity" />int QByteArray.capacity (<i>self</i>)</h3><p>Returns the maximum number of bytes that can be stored in the byte array without forcing a reallocation.</p>
102
<p>The sole purpose of this function is to provide a means of fine tuning <a href="qbytearray.html">QByteArray</a>'s memory usage. In general, you will rarely ever need to call this function. If you want to know how many bytes are in the byte array, call <a href="qbytearray.html#size">size</a>().</p>
103
<p>See also <a href="qbytearray.html#reserve">reserve</a>() and <a href="qbytearray.html#squeeze">squeeze</a>().</p>
104
<a name="//apple_ref/cpp/instm/QByteArray/chop" />
237
<h3 class="fn"><a name="capacity" />int QByteArray.capacity (<i>self</i>)</h3><p>Returns the maximum number of bytes that can be stored in the
238
byte array without forcing a reallocation.</p>
239
<p>The sole purpose of this function is to provide a means of fine
240
tuning <a href="qbytearray.html">QByteArray</a>'s memory usage. In
241
general, you will rarely ever need to call this function. If you
242
want to know how many bytes are in the byte array, call <a href="qbytearray.html#size">size</a>().</p>
243
<p>See also <a href="qbytearray.html#reserve">reserve</a>() and
244
<a href="qbytearray.html#squeeze">squeeze</a>().</p>
105
247
<h3 class="fn"><a name="chop" />QByteArray.chop (<i>self</i>, int)</h3><p>Removes <i>n</i> bytes from the end of the byte array.</p>
106
<p>If <i>n</i> is greater than <a href="qbytearray.html#size">size</a>(), the result is an empty byte array.</p>
248
<p>If <i>n</i> is greater than <a href="qbytearray.html#size">size</a>(), the result is an empty byte
108
<pre> QByteArray ba("STARTTLS\r\n");
109
ba.chop(2); <span class="comment">// ba == "STARTTLS"</span></pre>
110
<p>See also <a href="qbytearray.html#truncate">truncate</a>(), <a href="qbytearray.html#resize">resize</a>(), and <a href="qbytearray.html#left">left</a>().</p>
111
<a name="//apple_ref/cpp/instm/QByteArray/clear" />
251
<pre class="highlightedCode brush: cpp">
252
QByteArray ba("STARTTLS\r\n");
253
ba.chop(2); <span class="comment">// ba == "STARTTLS"</span>
255
<p>See also <a href="qbytearray.html#truncate">truncate</a>(),
256
<a href="qbytearray.html#resize">resize</a>(), and <a href="qbytearray.html#left">left</a>().</p>
112
259
<h3 class="fn"><a name="clear" />QByteArray.clear (<i>self</i>)</h3><p>Clears the contents of the byte array and makes it empty.</p>
113
<p>See also <a href="qbytearray.html#resize">resize</a>() and <a href="qbytearray.html#isEmpty">isEmpty</a>().</p>
114
<a name="//apple_ref/cpp/instm/QByteArray/constData" />
115
<h3 class="fn"><a name="contains" />bool QByteArray.contains (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns true if the byte array contains an occurrence of the byte array <i>ba</i>; otherwise returns false.</p>
116
<p>See also <a href="qbytearray.html#indexOf">indexOf</a>() and <a href="qbytearray.html#count">count</a>().</p>
117
<h3 class="fn"><a name="count" />int QByteArray.count (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns the number of (potentially overlapping) occurrences of byte array <i>ba</i> in this byte array.</p>
118
<p>See also <a href="qbytearray.html#contains">contains</a>() and <a href="qbytearray.html#indexOf">indexOf</a>().</p>
260
<p>See also <a href="qbytearray.html#resize">resize</a>() and
261
<a href="qbytearray.html#isEmpty">isEmpty</a>().</p>
264
<h3 class="fn"><a name="contains" />bool QByteArray.contains (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns true if the byte array contains an occurrence of the
265
byte array <i>ba</i>; otherwise returns false.</p>
266
<p>See also <a href="qbytearray.html#indexOf">indexOf</a>() and
267
<a href="qbytearray.html#count">count</a>().</p>
270
<h3 class="fn"><a name="count" />int QByteArray.count (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns the number of (potentially overlapping) occurrences of
271
byte array <i>ba</i> in this byte array.</p>
272
<p>See also <a href="qbytearray.html#contains">contains</a>() and
273
<a href="qbytearray.html#indexOf">indexOf</a>().</p>
119
276
<h3 class="fn"><a name="count-2" />int QByteArray.count (<i>self</i>)</h3><p>This is an overloaded function.</p>
120
<p>Returns the number of (potentially overlapping) occurrences of string <i>str</i> in the byte array.</p>
121
<h3 class="fn"><a name="data" />str QByteArray.data (<i>self</i>)</h3><p>Returns a pointer to the data stored in the byte array. The pointer can be used to access and modify the bytes that compose the array. The data is '\0'-terminated, i.e. the number of bytes in the returned character string is <a href="qbytearray.html#size">size</a>() + 1 for the '\0' terminator.</p>
277
<p>Returns the number of (potentially overlapping) occurrences of
278
string <i>str</i> in the byte array.</p>
281
<h3 class="fn"><a name="data" />str QByteArray.data (<i>self</i>)</h3><p>Returns a pointer to the data stored in the byte array. The
282
pointer can be used to access and modify the bytes that compose the
283
array. The data is '\0'-terminated, i.e. the number of bytes in the
284
returned character string is <a href="qbytearray.html#size">size</a>() + 1 for the '\0' terminator.</p>
123
<pre> QByteArray ba("Hello world");
286
<pre class="highlightedCode brush: cpp">
287
QByteArray ba("Hello world");
124
288
char *data = ba.data();
126
290
cout << "[" << *data << "]" << endl;
129
<p>The pointer remains valid as long as the byte array isn't reallocated or destroyed. For read-only access, <a href="qbytearray.html#constData">constData</a>() is faster because it never causes a <a href="implicit-sharing.html#deep-copy">deep copy</a> to occur.</p>
130
<p>This function is mostly useful to pass a byte array to a function that accepts a <tt>const char *</tt>.</p>
131
<p>The following example makes a copy of the char* returned by data(), but it will corrupt the heap and cause a crash because it does not allocate a byte for the '\0' at the end:</p>
132
<pre> QString tmp = "test";
294
<p>The pointer remains valid as long as the byte array isn't
295
reallocated or destroyed. For read-only access, <a href="qbytearray.html#constData">constData</a>() is faster because it
296
never causes a <a href="implicit-sharing.html#deep-copy">deep
297
copy</a> to occur.</p>
298
<p>This function is mostly useful to pass a byte array to a
299
function that accepts a <tt>const char *</tt>.</p>
300
<p>The following example makes a copy of the char* returned by
301
data(), but it will corrupt the heap and cause a crash because it
302
does not allocate a byte for the '\0' at the end:</p>
303
<pre class="highlightedCode brush: cpp">
304
QString tmp = "test";
133
305
QByteArray text = tmp.toLocal8Bit();
134
306
char *data = new char[text.size()]
135
307
strcpy(data, text.data());
136
delete [] data;</pre>
137
310
<p>This one allocates the correct amount of space:</p>
138
<pre> QString tmp = "test";
311
<pre class="highlightedCode brush: cpp">
312
QString tmp = "test";
139
313
QByteArray text = tmp.toLocal8Bit();
140
314
char *data = new char[text.size() + 1]
141
315
strcpy(data, text.data());
142
delete [] data;</pre>
143
<p>Note: A <a href="qbytearray.html">QByteArray</a> can store any byte values including '\0's, but most functions that take <tt>char *</tt> arguments assume that the data ends at the first '\0' they encounter.</p>
144
<p>See also <a href="qbytearray.html#constData">constData</a>() and <a href="qbytearray.html#operator-5b-5d">operator[]</a>().</p>
145
<h3 class="fn"><a name="endsWith" />bool QByteArray.endsWith (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns true if this byte array ends with byte array <i>ba</i>; otherwise returns false.</p>
318
<p>Note: A <a href="qbytearray.html">QByteArray</a> can store any
319
byte values including '\0's, but most functions that take <tt>char
320
*</tt> arguments assume that the data ends at the first '\0' they
322
<p>See also <a href="qbytearray.html#constData">constData</a>() and
323
<a href="qbytearray.html#operator-5b-5d">operator[]</a>().</p>
326
<h3 class="fn"><a name="endsWith" />bool QByteArray.endsWith (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns true if this byte array ends with byte array <i>ba</i>;
327
otherwise returns false.</p>
147
<pre> QByteArray url("http:<span class="comment">//qt.nokia.com/index.html");</span>
329
<pre class="highlightedCode brush: cpp">
330
QByteArray url("http://qt.nokia.com/index.html");
148
331
if (url.endsWith(".html"))
150
<p>See also <a href="qbytearray.html#startsWith">startsWith</a>() and <a href="qbytearray.html#right">right</a>().</p>
151
<h3 class="fn"><a name="fill" /><a href="qbytearray.html">QByteArray</a> QByteArray.fill (<i>self</i>, str, int <i>size</i> = -1)</h3><p>Sets every byte in the byte array to character <i>ch</i>. If <i>size</i> is different from -1 (the default), the byte array is resized to size <i>size</i> beforehand.</p>
334
<p>See also <a href="qbytearray.html#startsWith">startsWith</a>()
335
and <a href="qbytearray.html#right">right</a>().</p>
338
<h3 class="fn"><a name="fill" /><a href="qbytearray.html">QByteArray</a> QByteArray.fill (<i>self</i>, str, int <i>size</i> = -1)</h3><p>Sets every byte in the byte array to character <i>ch</i>. If
339
<i>size</i> is different from -1 (the default), the byte array is
340
resized to size <i>size</i> beforehand.</p>
153
<pre> QByteArray ba("Istambul");
342
<pre class="highlightedCode brush: cpp">
343
QByteArray ba("Istambul");
155
345
<span class="comment"> // ba == "oooooooo"</span>
158
<span class="comment"> // ba == "XX"</span></pre>
348
<span class="comment"> // ba == "XX"</span>
159
350
<p>See also <a href="qbytearray.html#resize">resize</a>().</p>
160
<a name="//apple_ref/cpp/clm/QByteArray/fromBase64" />
161
<h3 class="fn"><a name="fromBase64" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromBase64 (<a href="qbytearray.html">QByteArray</a>)</h3><p>Returns a decoded copy of the Base64 array <i>base64</i>. Input is not checked for validity; invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.</p>
353
<h3 class="fn"><a name="fromBase64" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromBase64 (<a href="qbytearray.html">QByteArray</a>)</h3><p>Returns a decoded copy of the Base64 array <i>base64</i>. Input
354
is not checked for validity; invalid characters in the input are
355
skipped, enabling the decoding process to continue with subsequent
162
357
<p>For example:</p>
163
<pre> QByteArray text = QByteArray.fromBase64("UXQgaXMgZ3JlYXQh");
164
text.data(); <span class="comment">// returns "Qt is great</span>!"</pre>
165
<p>The algorithm used to decode Base64-encoded data is defined in <a href="http://www.rfc-editor.org/rfc/rfc2045.txt">RFC 2045</a>.</p>
358
<pre class="highlightedCode brush: cpp">
359
QByteArray text = QByteArray.fromBase64("UXQgaXMgZ3JlYXQh");
360
text.data(); <span class="comment">// returns "Qt is great</span>!"
362
<p>The algorithm used to decode Base64-encoded data is defined in
363
<a href="http://www.rfc-editor.org/rfc/rfc2045.txt">RFC
166
365
<p>See also <a href="qbytearray.html#toBase64">toBase64</a>().</p>
167
<a name="//apple_ref/cpp/clm/QByteArray/fromHex" />
168
<h3 class="fn"><a name="fromHex" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromHex (<a href="qbytearray.html">QByteArray</a>)</h3><p>Returns a decoded copy of the hex encoded array <i>hexEncoded</i>. Input is not checked for validity; invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.</p>
368
<h3 class="fn"><a name="fromHex" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromHex (<a href="qbytearray.html">QByteArray</a>)</h3><p>Returns a decoded copy of the hex encoded array
369
<i>hexEncoded</i>. Input is not checked for validity; invalid
370
characters in the input are skipped, enabling the decoding process
371
to continue with subsequent characters.</p>
169
372
<p>For example:</p>
170
<pre> QByteArray text = QByteArray.fromHex("517420697320677265617421");
171
text.data(); <span class="comment">// returns "Qt is great</span>!"</pre>
373
<pre class="highlightedCode brush: cpp">
374
QByteArray text = QByteArray.fromHex("517420697320677265617421");
375
text.data(); <span class="comment">// returns "Qt is great</span>!"
172
377
<p>See also <a href="qbytearray.html#toHex">toHex</a>().</p>
173
<a name="//apple_ref/cpp/clm/QByteArray/fromPercentEncoding" />
174
<h3 class="fn"><a name="fromPercentEncoding" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromPercentEncoding (<a href="qbytearray.html">QByteArray</a>, str <i>percent</i> = '%')</h3><p>Returns a decoded copy of the URI/URL-style percent-encoded <i>input</i>. The <i>percent</i> parameter allows you to replace the '%' character for another (for instance, '<a href="examples-overview.html">_</a>' or '=').</p>
380
<h3 class="fn"><a name="fromPercentEncoding" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromPercentEncoding (<a href="qbytearray.html">QByteArray</a>, str <i>percent</i> = '%')</h3><p>Returns a decoded copy of the URI/URL-style percent-encoded
381
<i>input</i>. The <i>percent</i> parameter allows you to replace
382
the '%' character for another (for instance, '<a href="index.html">_</a>' or '=').</p>
175
383
<p>For example:</p>
176
<pre> QByteArray text = QByteArray.fromPercentEncoding("Qt%20is%20great%33");
177
text.data(); <span class="comment">// returns "Qt is great</span>!"</pre>
384
<pre class="highlightedCode brush: cpp">
385
QByteArray text = QByteArray.fromPercentEncoding("Qt%20is%20great%33");
386
text.data(); <span class="comment">// returns "Qt is great</span>!"
178
388
<p>This function was introduced in Qt 4.4.</p>
179
<p>See also <a href="qbytearray.html#toPercentEncoding">toPercentEncoding</a>() and <a href="qurl.html#fromPercentEncoding">QUrl.fromPercentEncoding</a>().</p>
180
<a name="//apple_ref/cpp/clm/QByteArray/fromRawData" />
181
<h3 class="fn"><a name="fromRawData" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromRawData (str)</h3><p>Constructs a <a href="qbytearray.html">QByteArray</a> that uses the first <i>size</i> bytes of the <i>data</i> array. The bytes are <i>not</i> copied. The <a href="qbytearray.html">QByteArray</a> will contain the <i>data</i> pointer. The caller guarantees that <i>data</i> will not be deleted or modified as long as this <a href="qbytearray.html">QByteArray</a> and any copies of it exist that have not been modified. In other words, because <a href="qbytearray.html">QByteArray</a> is an <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a> class and the instance returned by this function contains the <i>data</i> pointer, the caller must not delete <i>data</i> or modify it directly as long as the returned <a href="qbytearray.html">QByteArray</a> and any copies exist. However, <a href="qbytearray.html">QByteArray</a> does not take ownership of <i>data</i>, so the <a href="qbytearray.html">QByteArray</a> destructor will never delete the raw <i>data</i>, even when the last <a href="qbytearray.html">QByteArray</a> referring to <i>data</i> is destroyed.</p>
182
<p>A subsequent attempt to modify the contents of the returned <a href="qbytearray.html">QByteArray</a> or any copy made from it will cause it to create a deep copy of the <i>data</i> array before doing the modification. This ensures that the raw <i>data</i> array itself will never be modified by <a href="qbytearray.html">QByteArray</a>.</p>
183
<p>Here is an example of how to read data using a <a href="qdatastream.html">QDataStream</a> on raw data in memory without copying the raw data into a <a href="qbytearray.html">QByteArray</a>:</p>
184
<pre> static const char mydata[] = {
389
<p>See also <a href="qbytearray.html#toPercentEncoding">toPercentEncoding</a>() and
390
<a href="qurl.html#fromPercentEncoding">QUrl.fromPercentEncoding</a>().</p>
393
<h3 class="fn"><a name="fromRawData" /><a href="qbytearray.html">QByteArray</a> QByteArray.fromRawData (str)</h3><p>Constructs a <a href="qbytearray.html">QByteArray</a> that uses
394
the first <i>size</i> bytes of the <i>data</i> array. The bytes are
395
<i>not</i> copied. The <a href="qbytearray.html">QByteArray</a>
396
will contain the <i>data</i> pointer. The caller guarantees that
397
<i>data</i> will not be deleted or modified as long as this
398
<a href="qbytearray.html">QByteArray</a> and any copies of it exist
399
that have not been modified. In other words, because <a href="qbytearray.html">QByteArray</a> is an <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a>
400
class and the instance returned by this function contains the
401
<i>data</i> pointer, the caller must not delete <i>data</i> or
402
modify it directly as long as the returned <a href="qbytearray.html">QByteArray</a> and any copies exist. However,
403
<a href="qbytearray.html">QByteArray</a> does not take ownership of
404
<i>data</i>, so the <a href="qbytearray.html">QByteArray</a>
405
destructor will never delete the raw <i>data</i>, even when the
406
last <a href="qbytearray.html">QByteArray</a> referring to
407
<i>data</i> is destroyed.</p>
408
<p>A subsequent attempt to modify the contents of the returned
409
<a href="qbytearray.html">QByteArray</a> or any copy made from it
410
will cause it to create a deep copy of the <i>data</i> array before
411
doing the modification. This ensures that the raw <i>data</i> array
412
itself will never be modified by <a href="qbytearray.html">QByteArray</a>.</p>
413
<p>Here is an example of how to read data using a <a href="qdatastream.html">QDataStream</a> on raw data in memory without
414
copying the raw data into a <a href="qbytearray.html">QByteArray</a>:</p>
415
<pre class="highlightedCode brush: cpp">
416
static const char mydata[] = {
185
417
0x00, 0x00, 0x03, 0x84, 0x78, 0x9c, 0x3b, 0x76,
186
418
0xec, 0x18, 0xc3, 0x31, 0x0a, 0xf1, 0xcc, 0x99,
191
423
QByteArray data = QByteArray.fromRawData(mydata, sizeof(mydata));
192
424
QDataStream in(&data, QIODevice.ReadOnly);
194
<p><b>Warning:</b> A byte array created with fromRawData() is <i>not</i> null-terminated, unless the raw data contains a 0 character at position <i>size</i>. While that does not matter for <a href="qdatastream.html">QDataStream</a> or functions like <a href="qbytearray.html#indexOf">indexOf</a>(), passing the byte array to a function accepting a <tt>const char *</tt> expected to be '\0'-terminated will fail.</p>
195
<p>See also <a href="qbytearray.html#data">data</a>() and <a href="qbytearray.html#constData">constData</a>().</p>
196
<a name="//apple_ref/cpp/instm/QByteArray/indexOf" />
197
<h3 class="fn"><a name="indexOf" />int QByteArray.indexOf (<i>self</i>, <a href="qbytearray.html">QByteArray</a>, int <i>from</i> = 0)</h3><p>Returns the index position of the first occurrence of the byte array <i>ba</i> in this byte array, searching forward from index position <i>from</i>. Returns -1 if <i>ba</i> could not be found.</p>
427
<p><b>Warning:</b> A byte array created with fromRawData() is
428
<i>not</i> null-terminated, unless the raw data contains a 0
429
character at position <i>size</i>. While that does not matter for
430
<a href="qdatastream.html">QDataStream</a> or functions like
431
<a href="qbytearray.html#indexOf">indexOf</a>(), passing the byte
432
array to a function accepting a <tt>const char *</tt> expected to
433
be '\0'-terminated will fail.</p>
434
<p>See also <a href="qbytearray.html#setRawData">setRawData</a>(),
435
<a href="qbytearray.html#data">data</a>(), and <a href="qbytearray.html#constData">constData</a>().</p>
438
<h3 class="fn"><a name="indexOf" />int QByteArray.indexOf (<i>self</i>, <a href="qbytearray.html">QByteArray</a>, int <i>from</i> = 0)</h3><p>Returns the index position of the first occurrence of the byte
439
array <i>ba</i> in this byte array, searching forward from index
440
position <i>from</i>. Returns -1 if <i>ba</i> could not be
199
<pre> QByteArray x("sticky question");
443
<pre class="highlightedCode brush: cpp">
444
QByteArray x("sticky question");
200
445
QByteArray y("sti");
201
446
x.indexOf(y); <span class="comment">// returns 0</span>
202
447
x.indexOf(y, 1); <span class="comment">// returns 10</span>
203
448
x.indexOf(y, 10); <span class="comment">// returns 10</span>
204
x.indexOf(y, 11); <span class="comment">// returns -1</span></pre>
449
x.indexOf(y, 11); <span class="comment">// returns -1</span>
205
451
<p>See also <a href="qbytearray.html#lastIndexOf">lastIndexOf</a>(), <a href="qbytearray.html#contains">contains</a>(), and <a href="qbytearray.html#count">count</a>().</p>
206
454
<h3 class="fn"><a name="indexOf-2" />int QByteArray.indexOf (<i>self</i>, QString, int <i>from</i> = 0)</h3><p>This is an overloaded function.</p>
207
<p>Returns the index position of the first occurrence of the string <i>str</i> in the byte array, searching forward from index position <i>from</i>. Returns -1 if <i>str</i> could not be found.</p>
208
<p>The Unicode data is converted into 8-bit characters using <a href="qstring.html#toAscii">QString.toAscii</a>().</p>
209
<p>If the <a href="qstring.html">QString</a> contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining <tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications. You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly if you want to convert the data to <tt>const char *</tt>.</p>
210
<h3 class="fn"><a name="insert" /><a href="qbytearray.html">QByteArray</a> QByteArray.insert (<i>self</i>, int, <a href="qbytearray.html">QByteArray</a>)</h3><p>Inserts the byte array <i>ba</i> at index position <i>i</i> and returns a reference to this byte array.</p>
455
<p>Returns the index position of the first occurrence of the string
456
<i>str</i> in the byte array, searching forward from index position
457
<i>from</i>. Returns -1 if <i>str</i> could not be found.</p>
458
<p>The Unicode data is converted into 8-bit characters using
459
<a href="qstring.html#toAscii">QString.toAscii</a>().</p>
460
<p>If the <a href="qstring.html">QString</a> contains non-ASCII
461
Unicode characters, using this function can lead to loss of
462
information. You can disable this function by defining
463
<tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications.
464
You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly
465
if you want to convert the data to <tt>const char *</tt>.</p>
468
<h3 class="fn"><a name="insert" /><a href="qbytearray.html">QByteArray</a> QByteArray.insert (<i>self</i>, int, <a href="qbytearray.html">QByteArray</a>)</h3><p>Inserts the byte array <i>ba</i> at index position <i>i</i> and
469
returns a reference to this byte array.</p>
212
<pre> QByteArray ba("Meal");
471
<pre class="highlightedCode brush: cpp">
472
QByteArray ba("Meal");
213
473
ba.insert(1, QByteArray("ontr"));
214
<span class="comment"> // ba == "Montreal"</span></pre>
474
<span class="comment"> // ba == "Montreal"</span>
215
476
<p>See also <a href="qbytearray.html#append">append</a>(), <a href="qbytearray.html#prepend">prepend</a>(), <a href="qbytearray.html#replace">replace</a>(), and <a href="qbytearray.html#remove">remove</a>().</p>
216
479
<h3 class="fn"><a name="insert-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.insert (<i>self</i>, int, QString)</h3><p>This is an overloaded function.</p>
217
<p>Inserts the string <i>str</i> at index position <i>i</i> in the byte array. The Unicode data is converted into 8-bit characters using <a href="qstring.html#toAscii">QString.toAscii</a>().</p>
218
<p>If <i>i</i> is greater than <a href="qbytearray.html#size">size</a>(), the array is first extended using <a href="qbytearray.html#resize">resize</a>().</p>
219
<p>If the <a href="qstring.html">QString</a> contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining <tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications. You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly if you want to convert the data to <tt>const char *</tt>.</p>
220
<h3 class="fn"><a name="isEmpty" />bool QByteArray.isEmpty (<i>self</i>)</h3><p>Returns true if the byte array has size 0; otherwise returns false.</p>
480
<p>Inserts the string <i>str</i> at index position <i>i</i> in the
481
byte array. The Unicode data is converted into 8-bit characters
482
using <a href="qstring.html#toAscii">QString.toAscii</a>().</p>
483
<p>If <i>i</i> is greater than <a href="qbytearray.html#size">size</a>(), the array is first extended
484
using <a href="qbytearray.html#resize">resize</a>().</p>
485
<p>If the <a href="qstring.html">QString</a> contains non-ASCII
486
Unicode characters, using this function can lead to loss of
487
information. You can disable this function by defining
488
<tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications.
489
You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly
490
if you want to convert the data to <tt>const char *</tt>.</p>
493
<h3 class="fn"><a name="isEmpty" />bool QByteArray.isEmpty (<i>self</i>)</h3><p>Returns true if the byte array has size 0; otherwise returns
222
<pre> QByteArray().isEmpty(); <span class="comment">// returns true</span>
496
<pre class="highlightedCode brush: cpp">
497
QByteArray().isEmpty(); <span class="comment">// returns true</span>
223
498
QByteArray("").isEmpty(); <span class="comment">// returns true</span>
224
QByteArray("abc").isEmpty(); <span class="comment">// returns false</span></pre>
499
QByteArray("abc").isEmpty(); <span class="comment">// returns false</span>
225
501
<p>See also <a href="qbytearray.html#size">size</a>().</p>
226
<a name="//apple_ref/cpp/instm/QByteArray/isNull" />
227
<h3 class="fn"><a name="isNull" />bool QByteArray.isNull (<i>self</i>)</h3><p>Returns true if this byte array is null; otherwise returns false.</p>
504
<h3 class="fn"><a name="isNull" />bool QByteArray.isNull (<i>self</i>)</h3><p>Returns true if this byte array is null; otherwise returns
229
<pre> QByteArray().isNull(); <span class="comment">// returns true</span>
507
<pre class="highlightedCode brush: cpp">
508
QByteArray().isNull(); <span class="comment">// returns true</span>
230
509
QByteArray("").isNull(); <span class="comment">// returns false</span>
231
QByteArray("abc").isNull(); <span class="comment">// returns false</span></pre>
232
<p>Qt makes a distinction between null byte arrays and empty byte arrays for historical reasons. For most applications, what matters is whether or not a byte array contains any data, and this can be determined using <a href="qbytearray.html#isEmpty">isEmpty</a>().</p>
510
QByteArray("abc").isNull(); <span class="comment">// returns false</span>
512
<p>Qt makes a distinction between null byte arrays and empty byte
513
arrays for historical reasons. For most applications, what matters
514
is whether or not a byte array contains any data, and this can be
515
determined using <a href="qbytearray.html#isEmpty">isEmpty</a>().</p>
233
516
<p>See also <a href="qbytearray.html#isEmpty">isEmpty</a>().</p>
234
<a name="//apple_ref/cpp/instm/QByteArray/lastIndexOf" />
235
<h3 class="fn"><a name="lastIndexOf" />int QByteArray.lastIndexOf (<i>self</i>, <a href="qbytearray.html">QByteArray</a>, int <i>from</i> = -1)</h3><p>Returns the index position of the last occurrence of the byte array <i>ba</i> in this byte array, searching backward from index position <i>from</i>. If <i>from</i> is -1 (the default), the search starts at the last byte. Returns -1 if <i>ba</i> could not be found.</p>
519
<h3 class="fn"><a name="lastIndexOf" />int QByteArray.lastIndexOf (<i>self</i>, <a href="qbytearray.html">QByteArray</a>, int <i>from</i> = -1)</h3><p>Returns the index position of the last occurrence of the byte
520
array <i>ba</i> in this byte array, searching backward from index
521
position <i>from</i>. If <i>from</i> is -1 (the default), the
522
search starts at the last byte. Returns -1 if <i>ba</i> could not
237
<pre> QByteArray x("crazy azimuths");
525
<pre class="highlightedCode brush: cpp">
526
QByteArray x("crazy azimuths");
238
527
QByteArray y("az");
239
528
x.lastIndexOf(y); <span class="comment">// returns 6</span>
240
529
x.lastIndexOf(y, 6); <span class="comment">// returns 6</span>
241
530
x.lastIndexOf(y, 5); <span class="comment">// returns 2</span>
242
x.lastIndexOf(y, 1); <span class="comment">// returns -1</span></pre>
243
<p>See also <a href="qbytearray.html#indexOf">indexOf</a>(), <a href="qbytearray.html#contains">contains</a>(), and <a href="qbytearray.html#count">count</a>().</p>
531
x.lastIndexOf(y, 1); <span class="comment">// returns -1</span>
533
<p>See also <a href="qbytearray.html#indexOf">indexOf</a>(),
534
<a href="qbytearray.html#contains">contains</a>(), and <a href="qbytearray.html#count">count</a>().</p>
244
537
<h3 class="fn"><a name="lastIndexOf-2" />int QByteArray.lastIndexOf (<i>self</i>, QString, int <i>from</i> = -1)</h3><p>This is an overloaded function.</p>
245
<p>Returns the index position of the last occurrence of the string <i>str</i> in the byte array, searching backward from index position <i>from</i>. If <i>from</i> is -1 (the default), the search starts at the last (<a href="qbytearray.html#size">size</a>() - 1) byte. Returns -1 if <i>str</i> could not be found.</p>
246
<p>The Unicode data is converted into 8-bit characters using <a href="qstring.html#toAscii">QString.toAscii</a>().</p>
247
<p>If the <a href="qstring.html">QString</a> contains non-ASCII Unicode characters, using this function can lead to loss of information. You can disable this function by defining <tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications. You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly if you want to convert the data to <tt>const char *</tt>.</p>
248
<h3 class="fn"><a name="left" /><a href="qbytearray.html">QByteArray</a> QByteArray.left (<i>self</i>, int)</h3><p>Returns a byte array that contains the leftmost <i>len</i> bytes of this byte array.</p>
249
<p>The entire byte array is returned if <i>len</i> is greater than <a href="qbytearray.html#size">size</a>().</p>
538
<p>Returns the index position of the last occurrence of the string
539
<i>str</i> in the byte array, searching backward from index
540
position <i>from</i>. If <i>from</i> is -1 (the default), the
541
search starts at the last (<a href="qbytearray.html#size">size</a>() - 1) byte. Returns -1 if
542
<i>str</i> could not be found.</p>
543
<p>The Unicode data is converted into 8-bit characters using
544
<a href="qstring.html#toAscii">QString.toAscii</a>().</p>
545
<p>If the <a href="qstring.html">QString</a> contains non-ASCII
546
Unicode characters, using this function can lead to loss of
547
information. You can disable this function by defining
548
<tt>QT_NO_CAST_TO_ASCII</tt> when you compile your applications.
549
You then need to call <a href="qstring.html#toAscii">QString.toAscii</a>() (or <a href="qstring.html#toLatin1">QString.toLatin1</a>() or <a href="qstring.html#toUtf8">QString.toUtf8</a>() or <a href="qstring.html#toLocal8Bit">QString.toLocal8Bit</a>()) explicitly
550
if you want to convert the data to <tt>const char *</tt>.</p>
553
<h3 class="fn"><a name="left" /><a href="qbytearray.html">QByteArray</a> QByteArray.left (<i>self</i>, int)</h3><p>Returns a byte array that contains the leftmost <i>len</i> bytes
554
of this byte array.</p>
555
<p>The entire byte array is returned if <i>len</i> is greater than
556
<a href="qbytearray.html#size">size</a>().</p>
251
<pre> QByteArray x("Pineapple");
558
<pre class="highlightedCode brush: cpp">
559
QByteArray x("Pineapple");
252
560
QByteArray y = x.left(4);
253
<span class="comment"> // y == "Pine"</span></pre>
561
<span class="comment"> // y == "Pine"</span>
254
563
<p>See also <a href="qbytearray.html#right">right</a>(), <a href="qbytearray.html#mid">mid</a>(), <a href="qbytearray.html#startsWith">startsWith</a>(), and <a href="qbytearray.html#truncate">truncate</a>().</p>
255
<a name="//apple_ref/cpp/instm/QByteArray/leftJustified" />
256
<h3 class="fn"><a name="leftJustified" /><a href="qbytearray.html">QByteArray</a> QByteArray.leftJustified (<i>self</i>, int, str <i>fill</i> = ' ', bool <i>truncate</i> = False)</h3><p>Returns a byte array of size <i>width</i> that contains this byte array padded by the <i>fill</i> character.</p>
257
<p>If <i>truncate</i> is false and the <a href="qbytearray.html#size">size</a>() of the byte array is more than <i>width</i>, then the returned byte array is a copy of this byte array.</p>
258
<p>If <i>truncate</i> is true and the <a href="qbytearray.html#size">size</a>() of the byte array is more than <i>width</i>, then any bytes in a copy of the byte array after position <i>width</i> are removed, and the copy is returned.</p>
566
<h3 class="fn"><a name="leftJustified" /><a href="qbytearray.html">QByteArray</a> QByteArray.leftJustified (<i>self</i>, int, str <i>fill</i> = ' ', bool <i>truncate</i> = False)</h3><p>Returns a byte array of size <i>width</i> that contains this
567
byte array padded by the <i>fill</i> character.</p>
568
<p>If <i>truncate</i> is false and the <a href="qbytearray.html#size">size</a>() of the byte array is more than
569
<i>width</i>, then the returned byte array is a copy of this byte
571
<p>If <i>truncate</i> is true and the <a href="qbytearray.html#size">size</a>() of the byte array is more than
572
<i>width</i>, then any bytes in a copy of the byte array after
573
position <i>width</i> are removed, and the copy is returned.</p>
260
<pre> QByteArray x("apple");
261
QByteArray y = x.leftJustified(8, '.'); <span class="comment">// y == "apple..."</span></pre>
575
<pre class="highlightedCode brush: cpp">
576
QByteArray x("apple");
577
QByteArray y = x.leftJustified(8, '.'); <span class="comment">// y == "apple..."</span>
262
579
<p>See also <a href="qbytearray.html#rightJustified">rightJustified</a>().</p>
263
<a name="//apple_ref/cpp/instm/QByteArray/length" />
264
582
<h3 class="fn"><a name="length" />int QByteArray.length (<i>self</i>)</h3><p>Same as <a href="qbytearray.html#size">size</a>().</p>
265
<a name="//apple_ref/cpp/instm/QByteArray/mid" />
266
<h3 class="fn"><a name="mid" /><a href="qbytearray.html">QByteArray</a> QByteArray.mid (<i>self</i>, int, int <i>length</i> = -1)</h3><p>Returns a byte array containing <i>len</i> bytes from this byte array, starting at position <i>pos</i>.</p>
267
<p>If <i>len</i> is -1 (the default), or <i>pos</i> + <i>len</i> >= <a href="qbytearray.html#size">size</a>(), returns a byte array containing all bytes starting at position <i>pos</i> until the end of the byte array.</p>
585
<h3 class="fn"><a name="mid" /><a href="qbytearray.html">QByteArray</a> QByteArray.mid (<i>self</i>, int, int <i>length</i> = -1)</h3><p>Returns a byte array containing <i>len</i> bytes from this byte
586
array, starting at position <i>pos</i>.</p>
587
<p>If <i>len</i> is -1 (the default), or <i>pos</i> + <i>len</i>
588
>= <a href="qbytearray.html#size">size</a>(), returns a byte
589
array containing all bytes starting at position <i>pos</i> until
590
the end of the byte array.</p>
269
<pre> QByteArray x("Five pineapples");
592
<pre class="highlightedCode brush: cpp">
593
QByteArray x("Five pineapples");
270
594
QByteArray y = x.mid(5, 4); <span class="comment">// y == "pine"</span>
271
QByteArray z = x.mid(5); <span class="comment">// z == "pineapples"</span></pre>
595
QByteArray z = x.mid(5); <span class="comment">// z == "pineapples"</span>
272
597
<p>See also <a href="qbytearray.html#left">left</a>() and <a href="qbytearray.html#right">right</a>().</p>
273
<a name="//apple_ref/cpp/clm/QByteArray/number" />
274
<h3 class="fn"><a name="number" /><a href="qbytearray.html">QByteArray</a> QByteArray.number (int, int <i>base</i> = 10)</h3><p>Returns a byte array containing the string equivalent of the number <i>n</i> to base <i>base</i> (10 by default). The <i>base</i> can be any value between 2 and 36.</p>
600
<h3 class="fn"><a name="number" /><a href="qbytearray.html">QByteArray</a> QByteArray.number (int, int <i>base</i> = 10)</h3><p>Returns a byte array containing the string equivalent of the
601
number <i>n</i> to base <i>base</i> (10 by default). The
602
<i>base</i> can be any value between 2 and 36.</p>
604
<pre class="highlightedCode brush: cpp">
277
606
QByteArray.number(n); <span class="comment">// returns "63"</span>
278
607
QByteArray.number(n, 16); <span class="comment">// returns "3f"</span>
279
QByteArray.number(n, 16).toUpper(); <span class="comment">// returns "3F"</span></pre>
280
<p><b>Note:</b> The format of the number is not localized; the default C locale is used irrespective of the user's locale.</p>
281
<p>See also <a href="qbytearray.html#setNum">setNum</a>() and <a href="qbytearray.html#toInt">toInt</a>().</p>
608
QByteArray.number(n, 16).toUpper(); <span class="comment">// returns "3F"</span>
610
<p><b>Note:</b> The format of the number is not localized; the
611
default C locale is used irrespective of the user's locale.</p>
612
<p>See also <a href="qbytearray.html#setNum">setNum</a>() and
613
<a href="qbytearray.html#toInt">toInt</a>().</p>
282
616
<h3 class="fn"><a name="number-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.number (float, str <i>format</i> = 'g', int <i>precision</i> = 6)</h3><p>This is an overloaded function.</p>
283
617
<p>See also <a href="qbytearray.html#toUInt">toUInt</a>().</p>
284
620
<h3 class="fn"><a name="number-3" /><a href="qbytearray.html">QByteArray</a> QByteArray.number (int, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
285
621
<p>See also <a href="qbytearray.html#toLongLong">toLongLong</a>().</p>
286
624
<h3 class="fn"><a name="number-4" /><a href="qbytearray.html">QByteArray</a> QByteArray.number (int, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
287
625
<p>See also <a href="qbytearray.html#toULongLong">toULongLong</a>().</p>
288
<h3 class="fn"><a name="prepend" /><a href="qbytearray.html">QByteArray</a> QByteArray.prepend (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Prepends the byte array <i>ba</i> to this byte array and returns a reference to this byte array.</p>
628
<h3 class="fn"><a name="prepend" /><a href="qbytearray.html">QByteArray</a> QByteArray.prepend (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Prepends the byte array <i>ba</i> to this byte array and returns
629
a reference to this byte array.</p>
290
<pre> QByteArray x("ship");
631
<pre class="highlightedCode brush: cpp">
632
QByteArray x("ship");
291
633
QByteArray y("air");
293
<span class="comment"> // x == "airship"</span></pre>
635
<span class="comment"> // x == "airship"</span>
294
637
<p>This is the same as insert(0, <i>ba</i>).</p>
295
<p>Note: <a href="qbytearray.html">QByteArray</a> is an <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a> class. Consequently, if <i>this</i> is an empty <a href="qbytearray.html">QByteArray</a>, then <i>this</i> will just share the data held in <i>ba</i>. In this case, no copying of data is done.</p>
296
<p>See also <a href="qbytearray.html#append">append</a>() and <a href="qbytearray.html#insert">insert</a>().</p>
297
<h3 class="fn"><a name="push_back" />QByteArray.push_back (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>This function is provided for STL compatibility. It is equivalent to append(<i>other</i>).</p>
298
<h3 class="fn"><a name="push_front" />QByteArray.push_front (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>This function is provided for STL compatibility. It is equivalent to prepend(<i>other</i>).</p>
299
<h3 class="fn"><a name="remove" /><a href="qbytearray.html">QByteArray</a> QByteArray.remove (<i>self</i>, int, int)</h3><p>Removes <i>len</i> bytes from the array, starting at index position <i>pos</i>, and returns a reference to the array.</p>
300
<p>If <i>pos</i> is out of range, nothing happens. If <i>pos</i> is valid, but <i>pos</i> + <i>len</i> is larger than the size of the array, the array is truncated at position <i>pos</i>.</p>
638
<p>Note: <a href="qbytearray.html">QByteArray</a> is an <a href="implicit-sharing.html#implicitly-shared">implicitly shared</a>
639
class. Consequently, if <i>this</i> is an empty <a href="qbytearray.html">QByteArray</a>, then <i>this</i> will just share
640
the data held in <i>ba</i>. In this case, no copying of data is
642
<p>See also <a href="qbytearray.html#append">append</a>() and
643
<a href="qbytearray.html#insert">insert</a>().</p>
646
<h3 class="fn"><a name="push_back" />QByteArray.push_back (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>This function is provided for STL compatibility. It is
647
equivalent to append(<i>other</i>).</p>
650
<h3 class="fn"><a name="push_front" />QByteArray.push_front (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>This function is provided for STL compatibility. It is
651
equivalent to prepend(<i>other</i>).</p>
654
<h3 class="fn"><a name="remove" /><a href="qbytearray.html">QByteArray</a> QByteArray.remove (<i>self</i>, int, int)</h3><p>Removes <i>len</i> bytes from the array, starting at index
655
position <i>pos</i>, and returns a reference to the array.</p>
656
<p>If <i>pos</i> is out of range, nothing happens. If <i>pos</i> is
657
valid, but <i>pos</i> + <i>len</i> is larger than the size of the
658
array, the array is truncated at position <i>pos</i>.</p>
302
<pre> QByteArray ba("Montreal");
660
<pre class="highlightedCode brush: cpp">
661
QByteArray ba("Montreal");
304
<span class="comment"> // ba == "Meal"</span></pre>
305
<p>See also <a href="qbytearray.html#insert">insert</a>() and <a href="qbytearray.html#replace">replace</a>().</p>
306
<a name="//apple_ref/cpp/instm/QByteArray/repeated" />
307
<h3 class="fn"><a name="repeated" /><a href="qbytearray.html">QByteArray</a> QByteArray.repeated (<i>self</i>, int)</h3><p>Returns a copy of this byte array repeated the specified number of <i>times</i>.</p>
308
<p>If <i>times</i> is less than 1, an empty byte array is returned.</p>
663
<span class="comment"> // ba == "Meal"</span>
665
<p>See also <a href="qbytearray.html#insert">insert</a>() and
666
<a href="qbytearray.html#replace">replace</a>().</p>
669
<h3 class="fn"><a name="repeated" /><a href="qbytearray.html">QByteArray</a> QByteArray.repeated (<i>self</i>, int)</h3><p>Returns a copy of this byte array repeated the specified number
671
<p>If <i>times</i> is less than 1, an empty byte array is
310
<pre> QByteArray ba("ab");
311
ba.repeated(4); <span class="comment">// returns "abababab"</span></pre>
674
<pre class="highlightedCode brush: cpp">
676
ba.repeated(4); <span class="comment">// returns "abababab"</span>
312
678
<p>This function was introduced in Qt 4.5.</p>
313
<a name="//apple_ref/cpp/instm/QByteArray/replace" />
314
<h3 class="fn"><a name="replace" /><a href="qbytearray.html">QByteArray</a> QByteArray.replace (<i>self</i>, int, int, <a href="qbytearray.html">QByteArray</a>)</h3><p>Replaces <i>len</i> bytes from index position <i>pos</i> with the byte array <i>after</i>, and returns a reference to this byte array.</p>
681
<h3 class="fn"><a name="replace" /><a href="qbytearray.html">QByteArray</a> QByteArray.replace (<i>self</i>, int, int, <a href="qbytearray.html">QByteArray</a>)</h3><p>Replaces <i>len</i> bytes from index position <i>pos</i> with
682
the byte array <i>after</i>, and returns a reference to this byte
316
<pre> QByteArray x("Say yes!");
685
<pre class="highlightedCode brush: cpp">
686
QByteArray x("Say yes!");
317
687
QByteArray y("no");
318
688
x.replace(4, 3, y);
319
<span class="comment"> // x == "Say no</span>!"</pre>
320
<p>See also <a href="qbytearray.html#insert">insert</a>() and <a href="qbytearray.html#remove">remove</a>().</p>
689
<span class="comment"> // x == "Say no</span>!"
691
<p>See also <a href="qbytearray.html#insert">insert</a>() and
692
<a href="qbytearray.html#remove">remove</a>().</p>
321
695
<h3 class="fn"><a name="replace-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.replace (<i>self</i>, <a href="qbytearray.html">QByteArray</a>, <a href="qbytearray.html">QByteArray</a>)</h3><p>This is an overloaded function.</p>
696
<p>Replaces <i>len</i> bytes from index position <i>pos</i> with
697
the zero terminated string <i>after</i>.</p>
698
<p>Notice: this can change the length of the byte array.</p>
322
701
<h3 class="fn"><a name="replace-3" /><a href="qbytearray.html">QByteArray</a> QByteArray.replace (<i>self</i>, QString, <a href="qbytearray.html">QByteArray</a>)</h3><p>This is an overloaded function.</p>
323
<p>Replaces every occurrence of the byte array <i>before</i> with the byte array <i>after</i>.</p>
325
<pre> QByteArray ba("colour behaviour flavour neighbour");
326
ba.replace(QByteArray("ou"), QByteArray("o"));
327
<span class="comment"> // ba == "color behavior flavor neighbor"</span></pre>
328
<h3 class="fn"><a name="reserve" />QByteArray.reserve (<i>self</i>, int)</h3><p>Attempts to allocate memory for at least <i>size</i> bytes. If you know in advance how large the byte array will be, you can call this function, and if you call <a href="qbytearray.html#resize">resize</a>() often you are likely to get better performance. If <i>size</i> is an underestimate, the worst that will happen is that the <a href="qbytearray.html">QByteArray</a> will be a bit slower.</p>
329
<p>The sole purpose of this function is to provide a means of fine tuning <a href="qbytearray.html">QByteArray</a>'s memory usage. In general, you will rarely ever need to call this function. If you want to change the size of the byte array, call <a href="qbytearray.html#resize">resize</a>().</p>
330
<p>See also <a href="qbytearray.html#squeeze">squeeze</a>() and <a href="qbytearray.html#capacity">capacity</a>().</p>
331
<a name="//apple_ref/cpp/instm/QByteArray/resize" />
702
<p>Replaces <i>len</i> bytes from index position <i>pos</i> with
703
<i>alen</i> bytes from the string <i>after</i>. <i>after</i> is
704
allowed to have '\0' characters.</p>
705
<p>This function was introduced in Qt 4.7.</p>
708
<h3 class="fn"><a name="reserve" />QByteArray.reserve (<i>self</i>, int)</h3><p>Attempts to allocate memory for at least <i>size</i> bytes. If
709
you know in advance how large the byte array will be, you can call
710
this function, and if you call <a href="qbytearray.html#resize">resize</a>() often you are likely to get
711
better performance. If <i>size</i> is an underestimate, the worst
712
that will happen is that the <a href="qbytearray.html">QByteArray</a> will be a bit slower.</p>
713
<p>The sole purpose of this function is to provide a means of fine
714
tuning <a href="qbytearray.html">QByteArray</a>'s memory usage. In
715
general, you will rarely ever need to call this function. If you
716
want to change the size of the byte array, call <a href="qbytearray.html#resize">resize</a>().</p>
717
<p>See also <a href="qbytearray.html#squeeze">squeeze</a>() and
718
<a href="qbytearray.html#capacity">capacity</a>().</p>
332
721
<h3 class="fn"><a name="resize" />QByteArray.resize (<i>self</i>, int)</h3><p>Sets the size of the byte array to <i>size</i> bytes.</p>
333
<p>If <i>size</i> is greater than the current size, the byte array is extended to make it <i>size</i> bytes with the extra bytes added to the end. The new bytes are uninitialized.</p>
334
<p>If <i>size</i> is less than the current size, bytes are removed from the end.</p>
722
<p>If <i>size</i> is greater than the current size, the byte array
723
is extended to make it <i>size</i> bytes with the extra bytes added
724
to the end. The new bytes are uninitialized.</p>
725
<p>If <i>size</i> is less than the current size, bytes are removed
335
727
<p>See also <a href="qbytearray.html#size">size</a>().</p>
336
<a name="//apple_ref/cpp/instm/QByteArray/right" />
337
<h3 class="fn"><a name="right" /><a href="qbytearray.html">QByteArray</a> QByteArray.right (<i>self</i>, int)</h3><p>Returns a byte array that contains the rightmost <i>len</i> bytes of this byte array.</p>
338
<p>The entire byte array is returned if <i>len</i> is greater than <a href="qbytearray.html#size">size</a>().</p>
730
<h3 class="fn"><a name="right" /><a href="qbytearray.html">QByteArray</a> QByteArray.right (<i>self</i>, int)</h3><p>Returns a byte array that contains the rightmost <i>len</i>
731
bytes of this byte array.</p>
732
<p>The entire byte array is returned if <i>len</i> is greater than
733
<a href="qbytearray.html#size">size</a>().</p>
340
<pre> QByteArray x("Pineapple");
735
<pre class="highlightedCode brush: cpp">
736
QByteArray x("Pineapple");
341
737
QByteArray y = x.right(5);
342
<span class="comment"> // y == "apple"</span></pre>
343
<p>See also <a href="qbytearray.html#endsWith">endsWith</a>(), <a href="qbytearray.html#left">left</a>(), and <a href="qbytearray.html#mid">mid</a>().</p>
344
<a name="//apple_ref/cpp/instm/QByteArray/rightJustified" />
345
<h3 class="fn"><a name="rightJustified" /><a href="qbytearray.html">QByteArray</a> QByteArray.rightJustified (<i>self</i>, int, str <i>fill</i> = ' ', bool <i>truncate</i> = False)</h3><p>Returns a byte array of size <i>width</i> that contains the <i>fill</i> character followed by this byte array.</p>
346
<p>If <i>truncate</i> is false and the size of the byte array is more than <i>width</i>, then the returned byte array is a copy of this byte array.</p>
347
<p>If <i>truncate</i> is true and the size of the byte array is more than <i>width</i>, then the resulting byte array is truncated at position <i>width</i>.</p>
738
<span class="comment"> // y == "apple"</span>
740
<p>See also <a href="qbytearray.html#endsWith">endsWith</a>(),
741
<a href="qbytearray.html#left">left</a>(), and <a href="qbytearray.html#mid">mid</a>().</p>
744
<h3 class="fn"><a name="rightJustified" /><a href="qbytearray.html">QByteArray</a> QByteArray.rightJustified (<i>self</i>, int, str <i>fill</i> = ' ', bool <i>truncate</i> = False)</h3><p>Returns a byte array of size <i>width</i> that contains the
745
<i>fill</i> character followed by this byte array.</p>
746
<p>If <i>truncate</i> is false and the size of the byte array is
747
more than <i>width</i>, then the returned byte array is a copy of
749
<p>If <i>truncate</i> is true and the size of the byte array is
750
more than <i>width</i>, then the resulting byte array is truncated
751
at position <i>width</i>.</p>
349
<pre> QByteArray x("apple");
350
QByteArray y = x.rightJustified(8, '.'); <span class="comment">// y == "...apple"</span></pre>
753
<pre class="highlightedCode brush: cpp">
754
QByteArray x("apple");
755
QByteArray y = x.rightJustified(8, '.'); <span class="comment">// y == "...apple"</span>
351
757
<p>See also <a href="qbytearray.html#leftJustified">leftJustified</a>().</p>
352
<a name="//apple_ref/cpp/instm/QByteArray/setNum" />
353
<h3 class="fn"><a name="setNum" /><a href="qbytearray.html">QByteArray</a> QByteArray.setNum (<i>self</i>, int, int <i>base</i> = 10)</h3><p>Sets the byte array to the printed value of <i>n</i> in base <i>base</i> (10 by default) and returns a reference to the byte array. The <i>base</i> can be any value between 2 and 36.</p>
760
<h3 class="fn"><a name="setNum" /><a href="qbytearray.html">QByteArray</a> QByteArray.setNum (<i>self</i>, int, int <i>base</i> = 10)</h3><p>Sets the byte array to the printed value of <i>n</i> in base
761
<i>base</i> (10 by default) and returns a reference to the byte
762
array. The <i>base</i> can be any value between 2 and 36.</p>
764
<pre class="highlightedCode brush: cpp">
357
767
ba.setNum(n); <span class="comment">// ba == "63"</span>
358
ba.setNum(n, 16); <span class="comment">// ba == "3f"</span></pre>
359
<p><b>Note:</b> The format of the number is not localized; the default C locale is used irrespective of the user's locale.</p>
360
<p>See also <a href="qbytearray.html#number">number</a>() and <a href="qbytearray.html#toInt">toInt</a>().</p>
768
ba.setNum(n, 16); <span class="comment">// ba == "3f"</span>
770
<p><b>Note:</b> The format of the number is not localized; the
771
default C locale is used irrespective of the user's locale.</p>
772
<p>See also <a href="qbytearray.html#number">number</a>() and
773
<a href="qbytearray.html#toInt">toInt</a>().</p>
361
776
<h3 class="fn"><a name="setNum-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.setNum (<i>self</i>, float, str <i>format</i> = 'g', int <i>precision</i> = 6)</h3><p>This is an overloaded function.</p>
362
777
<p>See also <a href="qbytearray.html#toUInt">toUInt</a>().</p>
363
780
<h3 class="fn"><a name="setNum-3" /><a href="qbytearray.html">QByteArray</a> QByteArray.setNum (<i>self</i>, int, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
364
781
<p>See also <a href="qbytearray.html#toShort">toShort</a>().</p>
365
784
<h3 class="fn"><a name="setNum-4" /><a href="qbytearray.html">QByteArray</a> QByteArray.setNum (<i>self</i>, int, int <i>base</i> = 10)</h3><p>This is an overloaded function.</p>
366
785
<p>See also <a href="qbytearray.html#toUShort">toUShort</a>().</p>
367
<h3 class="fn"><a name="simplified" /><a href="qbytearray.html">QByteArray</a> QByteArray.simplified (<i>self</i>)</h3><p>Returns a byte array that has whitespace removed from the start and the end, and which has each sequence of internal whitespace replaced with a single space.</p>
368
<p>Whitespace means any character for which the standard C++ isspace() function returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.</p>
788
<h3 class="fn"><a name="simplified" /><a href="qbytearray.html">QByteArray</a> QByteArray.simplified (<i>self</i>)</h3><p>Returns a byte array that has whitespace removed from the start
789
and the end, and which has each sequence of internal whitespace
790
replaced with a single space.</p>
791
<p>Whitespace means any character for which the standard C++
792
isspace() function returns true. This includes the ASCII characters
793
'\t', '\n', '\v', '\f', '\r', and ' '.</p>
370
<pre> QByteArray ba(" lots\t of\nwhitespace\r\n ");
795
<pre class="highlightedCode brush: cpp">
796
QByteArray ba(" lots\t of\nwhitespace\r\n ");
371
797
ba = ba.simplified();
372
<span class="comment"> // ba == "lots of whitespace";</span></pre>
798
<span class="comment"> // ba == "lots of whitespace";</span>
373
800
<p>See also <a href="qbytearray.html#trimmed">trimmed</a>().</p>
374
<a name="//apple_ref/cpp/instm/QByteArray/size" />
375
803
<h3 class="fn"><a name="size" />int QByteArray.size (<i>self</i>)</h3><p>Returns the number of bytes in this byte array.</p>
376
<p>The last byte in the byte array is at position size() - 1. In addition, <a href="qbytearray.html">QByteArray</a> ensures that the byte at position size() is always '\0', so that you can use the return value of <a href="qbytearray.html#data">data</a>() and <a href="qbytearray.html#constData">constData</a>() as arguments to functions that expect '\0'-terminated strings.</p>
804
<p>The last byte in the byte array is at position size() - 1. In
805
addition, <a href="qbytearray.html">QByteArray</a> ensures that the
806
byte at position size() is always '\0', so that you can use the
807
return value of <a href="qbytearray.html#data">data</a>() and
808
<a href="qbytearray.html#constData">constData</a>() as arguments to
809
functions that expect '\0'-terminated strings.</p>
378
<pre> QByteArray ba("Hello");
811
<pre class="highlightedCode brush: cpp">
812
QByteArray ba("Hello");
379
813
int n = ba.size(); <span class="comment">// n == 5</span>
380
814
ba.data()[0]; <span class="comment">// returns 'H'</span>
381
815
ba.data()[4]; <span class="comment">// returns 'o'</span>
382
ba.data()[5]; <span class="comment">// returns '\0'</span></pre>
383
<p>See also <a href="qbytearray.html#isEmpty">isEmpty</a>() and <a href="qbytearray.html#resize">resize</a>().</p>
384
<a name="//apple_ref/cpp/instm/QByteArray/split" />
385
<h3 class="fn"><a name="split" />list-of-QByteArray QByteArray.split (<i>self</i>, str)</h3><p>Splits the byte array into subarrays wherever <i>sep</i> occurs, and returns the list of those arrays. If <i>sep</i> does not match anywhere in the byte array, split() returns a single-element list containing this byte array.</p>
386
<a name="//apple_ref/cpp/instm/QByteArray/squeeze" />
816
ba.data()[5]; <span class="comment">// returns '\0'</span>
818
<p>See also <a href="qbytearray.html#isEmpty">isEmpty</a>() and
819
<a href="qbytearray.html#resize">resize</a>().</p>
822
<h3 class="fn"><a name="split" />list-of-QByteArray QByteArray.split (<i>self</i>, str)</h3><p>Splits the byte array into subarrays wherever <i>sep</i> occurs,
823
and returns the list of those arrays. If <i>sep</i> does not match
824
anywhere in the byte array, split() returns a single-element list
825
containing this byte array.</p>
387
828
<h3 class="fn"><a name="squeeze" />QByteArray.squeeze (<i>self</i>)</h3><p>Releases any memory not required to store the array's data.</p>
388
<p>The sole purpose of this function is to provide a means of fine tuning <a href="qbytearray.html">QByteArray</a>'s memory usage. In general, you will rarely ever need to call this function.</p>
389
<p>See also <a href="qbytearray.html#reserve">reserve</a>() and <a href="qbytearray.html#capacity">capacity</a>().</p>
390
<a name="//apple_ref/cpp/instm/QByteArray/startsWith" />
391
<h3 class="fn"><a name="startsWith" />bool QByteArray.startsWith (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns true if this byte array starts with byte array <i>ba</i>; otherwise returns false.</p>
829
<p>The sole purpose of this function is to provide a means of fine
830
tuning <a href="qbytearray.html">QByteArray</a>'s memory usage. In
831
general, you will rarely ever need to call this function.</p>
832
<p>See also <a href="qbytearray.html#reserve">reserve</a>() and
833
<a href="qbytearray.html#capacity">capacity</a>().</p>
836
<h3 class="fn"><a name="startsWith" />bool QByteArray.startsWith (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><p>Returns true if this byte array starts with byte array
837
<i>ba</i>; otherwise returns false.</p>
393
<pre> QByteArray url("ftp:<span class="comment">//ftp.qt.nokia.com/");</span>
839
<pre class="highlightedCode brush: cpp">
840
QByteArray url("ftp://ftp.qt.nokia.com/");
394
841
if (url.startsWith("ftp:"))
396
<p>See also <a href="qbytearray.html#endsWith">endsWith</a>() and <a href="qbytearray.html#left">left</a>().</p>
844
<p>See also <a href="qbytearray.html#endsWith">endsWith</a>() and
845
<a href="qbytearray.html#left">left</a>().</p>
397
848
<h3 class="fn"><a name="toBase64" /><a href="qbytearray.html">QByteArray</a> QByteArray.toBase64 (<i>self</i>)</h3><p>Returns a copy of the byte array, encoded as Base64.</p>
398
<pre> QByteArray text("Qt is great!");
399
text.toBase64(); <span class="comment">// returns "UXQgaXMgZ3JlYXQh"</span></pre>
400
<p>The algorithm used to encode Base64-encoded data is defined in <a href="http://www.rfc-editor.org/rfc/rfc2045.txt">RFC 2045</a>.</p>
849
<pre class="highlightedCode brush: cpp">
850
QByteArray text("Qt is great!");
851
text.toBase64(); <span class="comment">// returns "UXQgaXMgZ3JlYXQh"</span>
853
<p>The algorithm used to encode Base64-encoded data is defined in
854
<a href="http://www.rfc-editor.org/rfc/rfc2045.txt">RFC
401
856
<p>See also <a href="qbytearray.html#fromBase64">fromBase64</a>().</p>
402
<a name="//apple_ref/cpp/instm/QByteArray/toDouble" />
403
859
<h3 class="fn"><a name="toDouble" />(float, bool <i>ok</i>) QByteArray.toDouble (<i>self</i>)</h3><p>Returns the byte array converted to a <tt>double</tt> value.</p>
404
860
<p>Returns 0.0 if the conversion fails.</p>
405
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
406
<pre> QByteArray string("1234.56");
407
double a = string.toDouble(); <span class="comment">// a == 1234.56</span></pre>
408
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
861
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
862
is set to false; otherwise *<i>ok</i> is set to true.</p>
863
<pre class="highlightedCode brush: cpp">
864
QByteArray string("1234.56");
865
double a = string.toDouble(); <span class="comment">// a == 1234.56</span>
867
<p><b>Note:</b> The conversion of the number is performed in the
868
default C locale, irrespective of the user's locale.</p>
409
869
<p>See also <a href="qbytearray.html#number">number</a>().</p>
410
<a name="//apple_ref/cpp/instm/QByteArray/toFloat" />
411
872
<h3 class="fn"><a name="toFloat" />(float, bool <i>ok</i>) QByteArray.toFloat (<i>self</i>)</h3><p>Returns the byte array converted to a <tt>float</tt> value.</p>
412
873
<p>Returns 0.0 if the conversion fails.</p>
413
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
414
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
874
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
875
is set to false; otherwise *<i>ok</i> is set to true.</p>
876
<p><b>Note:</b> The conversion of the number is performed in the
877
default C locale, irrespective of the user's locale.</p>
415
878
<p>See also <a href="qbytearray.html#number">number</a>().</p>
416
<a name="//apple_ref/cpp/instm/QByteArray/toHex" />
417
<h3 class="fn"><a name="toHex" /><a href="qbytearray.html">QByteArray</a> QByteArray.toHex (<i>self</i>)</h3><p>Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f.</p>
881
<h3 class="fn"><a name="toHex" /><a href="qbytearray.html">QByteArray</a> QByteArray.toHex (<i>self</i>)</h3><p>Returns a hex encoded copy of the byte array. The hex encoding
882
uses the numbers 0-9 and the letters a-f.</p>
418
883
<p>See also <a href="qbytearray.html#fromHex">fromHex</a>().</p>
419
<a name="//apple_ref/cpp/instm/QByteArray/toInt" />
420
<h3 class="fn"><a name="toInt" />(int, bool <i>ok</i>) QByteArray.toInt (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>int</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
421
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
886
<h3 class="fn"><a name="toInt" />(int, bool <i>ok</i>) QByteArray.toInt (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>int</tt> using base
887
<i>base</i>, which is 10 by default and must be between 2 and 36,
889
<p>If <i>base</i> is 0, the base is determined automatically using
890
the following rules: If the byte array begins with "0x", it is
891
assumed to be hexadecimal; if it begins with "0", it is assumed to
892
be octal; otherwise it is assumed to be decimal.</p>
422
893
<p>Returns 0 if the conversion fails.</p>
423
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
424
<pre> QByteArray str("FF");
894
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
895
is set to false; otherwise *<i>ok</i> is set to true.</p>
896
<pre class="highlightedCode brush: cpp">
897
QByteArray str("FF");
426
899
int hex = str.toInt(&ok, 16); <span class="comment">// hex == 255, ok == true</span>
427
int dec = str.toInt(&ok, 10); <span class="comment">// dec == 0, ok == false</span></pre>
428
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
900
int dec = str.toInt(&ok, 10); <span class="comment">// dec == 0, ok == false</span>
902
<p><b>Note:</b> The conversion of the number is performed in the
903
default C locale, irrespective of the user's locale.</p>
429
904
<p>See also <a href="qbytearray.html#number">number</a>().</p>
430
<a name="//apple_ref/cpp/instm/QByteArray/toLong" />
431
<h3 class="fn"><a name="toLong" />(int, bool <i>ok</i>) QByteArray.toLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to a <tt>long</tt> int using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
432
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
907
<h3 class="fn"><a name="toLong" />(int, bool <i>ok</i>) QByteArray.toLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to a <tt>long</tt> int using
908
base <i>base</i>, which is 10 by default and must be between 2 and
910
<p>If <i>base</i> is 0, the base is determined automatically using
911
the following rules: If the byte array begins with "0x", it is
912
assumed to be hexadecimal; if it begins with "0", it is assumed to
913
be octal; otherwise it is assumed to be decimal.</p>
433
914
<p>Returns 0 if the conversion fails.</p>
434
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
435
<pre> QByteArray str("FF");
915
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
916
is set to false; otherwise *<i>ok</i> is set to true.</p>
917
<pre class="highlightedCode brush: cpp">
918
QByteArray str("FF");
437
920
long hex = str.toLong(&ok, 16); <span class="comment">// hex == 255, ok == true</span>
438
long dec = str.toLong(&ok, 10); <span class="comment">// dec == 0, ok == false</span></pre>
439
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
921
long dec = str.toLong(&ok, 10); <span class="comment">// dec == 0, ok == false</span>
923
<p><b>Note:</b> The conversion of the number is performed in the
924
default C locale, irrespective of the user's locale.</p>
440
925
<p>This function was introduced in Qt 4.1.</p>
441
926
<p>See also <a href="qbytearray.html#number">number</a>().</p>
442
<a name="//apple_ref/cpp/instm/QByteArray/toLongLong" />
443
<h3 class="fn"><a name="toLongLong" />(int, bool <i>ok</i>) QByteArray.toLongLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to a <tt>long long</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
444
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
929
<h3 class="fn"><a name="toLongLong" />(int, bool <i>ok</i>) QByteArray.toLongLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to a <tt>long long</tt> using
930
base <i>base</i>, which is 10 by default and must be between 2 and
932
<p>If <i>base</i> is 0, the base is determined automatically using
933
the following rules: If the byte array begins with "0x", it is
934
assumed to be hexadecimal; if it begins with "0", it is assumed to
935
be octal; otherwise it is assumed to be decimal.</p>
445
936
<p>Returns 0 if the conversion fails.</p>
446
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
447
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
937
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
938
is set to false; otherwise *<i>ok</i> is set to true.</p>
939
<p><b>Note:</b> The conversion of the number is performed in the
940
default C locale, irrespective of the user's locale.</p>
448
941
<p>See also <a href="qbytearray.html#number">number</a>().</p>
449
<a name="//apple_ref/cpp/instm/QByteArray/toLower" />
450
<h3 class="fn"><a name="toLower" /><a href="qbytearray.html">QByteArray</a> QByteArray.toLower (<i>self</i>)</h3><p>Returns a lowercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.</p>
944
<h3 class="fn"><a name="toLower" /><a href="qbytearray.html">QByteArray</a> QByteArray.toLower (<i>self</i>)</h3><p>Returns a lowercase copy of the byte array. The bytearray is
945
interpreted as a Latin-1 encoded string.</p>
452
<pre> QByteArray x("Qt by NOKIA");
947
<pre class="highlightedCode brush: cpp">
948
QByteArray x("Qt by NOKIA");
453
949
QByteArray y = x.toLower();
454
<span class="comment"> // y == "qt by nokia"</span></pre>
455
<p>See also <a href="qbytearray.html#toUpper">toUpper</a>() and <a href="qbytearray.html#8-bit-character-comparisons">8-bit Character Comparisons</a>.</p>
456
<a name="//apple_ref/cpp/instm/QByteArray/toPercentEncoding" />
457
<h3 class="fn"><a name="toPercentEncoding" /><a href="qbytearray.html">QByteArray</a> QByteArray.toPercentEncoding (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>exclude</i> = QByteArray(), <a href="qbytearray.html">QByteArray</a> <i>include</i> = QByteArray(), str <i>percent</i> = '%')</h3><p>Returns a URI/URL-style percent-encoded copy of this byte array. The <i>percent</i> parameter allows you to override the default '%' character for another.</p>
458
<p>By default, this function will encode all characters that are not one of the following:</p>
459
<p>ALPHA ("a" to "z" and "A" to "Z") / DIGIT (0 to 9) / "-" / "." / "<a href="examples-overview.html">_</a>" / "~"</p>
460
<p>To prevent characters from being encoded pass them to <i>exclude</i>. To force characters to be encoded pass them to <i>include</i>. The <i>percent</i> character is always encoded.</p>
950
<span class="comment"> // y == "qt by nokia"</span>
952
<p>See also <a href="qbytearray.html#toUpper">toUpper</a>() and
953
<a href="qbytearray.html#8-bit-character-comparisons">8-bit
954
Character Comparisons</a>.</p>
957
<h3 class="fn"><a name="toPercentEncoding" /><a href="qbytearray.html">QByteArray</a> QByteArray.toPercentEncoding (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>exclude</i> = QByteArray(), <a href="qbytearray.html">QByteArray</a> <i>include</i> = QByteArray(), str <i>percent</i> = '%')</h3><p>Returns a URI/URL-style percent-encoded copy of this byte array.
958
The <i>percent</i> parameter allows you to override the default '%'
959
character for another.</p>
960
<p>By default, this function will encode all characters that are
961
not one of the following:</p>
962
<p>ALPHA ("a" to "z" and "A" to "Z") / DIGIT (0 to 9) / "-" / "." /
963
"<a href="index.html">_</a>" / "~"</p>
964
<p>To prevent characters from being encoded pass them to
965
<i>exclude</i>. To force characters to be encoded pass them to
966
<i>include</i>. The <i>percent</i> character is always encoded.</p>
462
<pre> QByteArray text = "{a fishy string?}";
968
<pre class="highlightedCode brush: cpp">
969
QByteArray text = "{a fishy string?}";
463
970
QByteArray ba = text.toPercentEncoding("{}", "s");
464
971
qDebug(ba.constData());
465
<span class="comment"> // prints "{a fi%73hy %73tring%3F}"</span></pre>
466
<p>The hex encoding uses the numbers 0-9 and the uppercase letters A-F.</p>
972
<span class="comment"> // prints "{a fi%73hy %73tring%3F}"</span>
974
<p>The hex encoding uses the numbers 0-9 and the uppercase letters
467
976
<p>This function was introduced in Qt 4.4.</p>
468
<p>See also <a href="qbytearray.html#fromPercentEncoding">fromPercentEncoding</a>() and <a href="qurl.html#toPercentEncoding">QUrl.toPercentEncoding</a>().</p>
469
<a name="//apple_ref/cpp/instm/QByteArray/toShort" />
470
<h3 class="fn"><a name="toShort" />(int, bool <i>ok</i>) QByteArray.toShort (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to a <tt>short</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
471
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
472
<p>Returns 0 if the conversion fails.</p>
473
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
474
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
475
<p>See also <a href="qbytearray.html#number">number</a>().</p>
476
<a name="//apple_ref/cpp/instm/QByteArray/toUInt" />
477
<h3 class="fn"><a name="toUInt" />(int, bool <i>ok</i>) QByteArray.toUInt (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned int</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
478
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
479
<p>Returns 0 if the conversion fails.</p>
480
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
481
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
482
<p>See also <a href="qbytearray.html#number">number</a>().</p>
483
<a name="//apple_ref/cpp/instm/QByteArray/toULong" />
484
<h3 class="fn"><a name="toULong" />(int, bool <i>ok</i>) QByteArray.toULong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned long int</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
485
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
486
<p>Returns 0 if the conversion fails.</p>
487
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
488
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
977
<p>See also <a href="qbytearray.html#fromPercentEncoding">fromPercentEncoding</a>() and
978
<a href="qurl.html#toPercentEncoding">QUrl.toPercentEncoding</a>().</p>
981
<h3 class="fn"><a name="toShort" />(int, bool <i>ok</i>) QByteArray.toShort (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to a <tt>short</tt> using base
982
<i>base</i>, which is 10 by default and must be between 2 and 36,
984
<p>If <i>base</i> is 0, the base is determined automatically using
985
the following rules: If the byte array begins with "0x", it is
986
assumed to be hexadecimal; if it begins with "0", it is assumed to
987
be octal; otherwise it is assumed to be decimal.</p>
988
<p>Returns 0 if the conversion fails.</p>
989
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
990
is set to false; otherwise *<i>ok</i> is set to true.</p>
991
<p><b>Note:</b> The conversion of the number is performed in the
992
default C locale, irrespective of the user's locale.</p>
993
<p>See also <a href="qbytearray.html#number">number</a>().</p>
996
<h3 class="fn"><a name="toUInt" />(int, bool <i>ok</i>) QByteArray.toUInt (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned int</tt>
997
using base <i>base</i>, which is 10 by default and must be between
999
<p>If <i>base</i> is 0, the base is determined automatically using
1000
the following rules: If the byte array begins with "0x", it is
1001
assumed to be hexadecimal; if it begins with "0", it is assumed to
1002
be octal; otherwise it is assumed to be decimal.</p>
1003
<p>Returns 0 if the conversion fails.</p>
1004
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
1005
is set to false; otherwise *<i>ok</i> is set to true.</p>
1006
<p><b>Note:</b> The conversion of the number is performed in the
1007
default C locale, irrespective of the user's locale.</p>
1008
<p>See also <a href="qbytearray.html#number">number</a>().</p>
1011
<h3 class="fn"><a name="toULong" />(int, bool <i>ok</i>) QByteArray.toULong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned long
1012
int</tt> using base <i>base</i>, which is 10 by default and must be
1013
between 2 and 36, or 0.</p>
1014
<p>If <i>base</i> is 0, the base is determined automatically using
1015
the following rules: If the byte array begins with "0x", it is
1016
assumed to be hexadecimal; if it begins with "0", it is assumed to
1017
be octal; otherwise it is assumed to be decimal.</p>
1018
<p>Returns 0 if the conversion fails.</p>
1019
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
1020
is set to false; otherwise *<i>ok</i> is set to true.</p>
1021
<p><b>Note:</b> The conversion of the number is performed in the
1022
default C locale, irrespective of the user's locale.</p>
489
1023
<p>This function was introduced in Qt 4.1.</p>
490
1024
<p>See also <a href="qbytearray.html#number">number</a>().</p>
491
<a name="//apple_ref/cpp/instm/QByteArray/toULongLong" />
492
<h3 class="fn"><a name="toULongLong" />(int, bool <i>ok</i>) QByteArray.toULongLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned long long</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
493
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
1027
<h3 class="fn"><a name="toULongLong" />(int, bool <i>ok</i>) QByteArray.toULongLong (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned long
1028
long</tt> using base <i>base</i>, which is 10 by default and must
1029
be between 2 and 36, or 0.</p>
1030
<p>If <i>base</i> is 0, the base is determined automatically using
1031
the following rules: If the byte array begins with "0x", it is
1032
assumed to be hexadecimal; if it begins with "0", it is assumed to
1033
be octal; otherwise it is assumed to be decimal.</p>
494
1034
<p>Returns 0 if the conversion fails.</p>
495
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
496
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
1035
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
1036
is set to false; otherwise *<i>ok</i> is set to true.</p>
1037
<p><b>Note:</b> The conversion of the number is performed in the
1038
default C locale, irrespective of the user's locale.</p>
497
1039
<p>See also <a href="qbytearray.html#number">number</a>().</p>
498
<a name="//apple_ref/cpp/instm/QByteArray/toUShort" />
499
<h3 class="fn"><a name="toUpper" /><a href="qbytearray.html">QByteArray</a> QByteArray.toUpper (<i>self</i>)</h3><p>Returns an uppercase copy of the byte array. The bytearray is interpreted as a Latin-1 encoded string.</p>
1042
<h3 class="fn"><a name="toUpper" /><a href="qbytearray.html">QByteArray</a> QByteArray.toUpper (<i>self</i>)</h3><p>Returns an uppercase copy of the byte array. The bytearray is
1043
interpreted as a Latin-1 encoded string.</p>
501
<pre> QByteArray x("Qt by NOKIA");
1045
<pre class="highlightedCode brush: cpp">
1046
QByteArray x("Qt by NOKIA");
502
1047
QByteArray y = x.toUpper();
503
<span class="comment"> // y == "QT BY NOKIA"</span></pre>
504
<p>See also <a href="qbytearray.html#toLower">toLower</a>() and <a href="qbytearray.html#8-bit-character-comparisons">8-bit Character Comparisons</a>.</p>
505
<a name="//apple_ref/cpp/instm/QByteArray/trimmed" />
506
<h3 class="fn"><a name="toUShort" />(int, bool <i>ok</i>) QByteArray.toUShort (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned short</tt> using base <i>base</i>, which is 10 by default and must be between 2 and 36, or 0.</p>
507
<p>If <i>base</i> is 0, the base is determined automatically using the following rules: If the byte array begins with "0x", it is assumed to be hexadecimal; if it begins with "0", it is assumed to be octal; otherwise it is assumed to be decimal.</p>
1048
<span class="comment"> // y == "QT BY NOKIA"</span>
1050
<p>See also <a href="qbytearray.html#toLower">toLower</a>() and
1051
<a href="qbytearray.html#8-bit-character-comparisons">8-bit
1052
Character Comparisons</a>.</p>
1055
<h3 class="fn"><a name="toUShort" />(int, bool <i>ok</i>) QByteArray.toUShort (<i>self</i>, int <i>base</i> = 10)</h3><p>Returns the byte array converted to an <tt>unsigned short</tt>
1056
using base <i>base</i>, which is 10 by default and must be between
1058
<p>If <i>base</i> is 0, the base is determined automatically using
1059
the following rules: If the byte array begins with "0x", it is
1060
assumed to be hexadecimal; if it begins with "0", it is assumed to
1061
be octal; otherwise it is assumed to be decimal.</p>
508
1062
<p>Returns 0 if the conversion fails.</p>
509
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i> is set to false; otherwise *<i>ok</i> is set to true.</p>
510
<p><b>Note:</b> The conversion of the number is performed in the default C locale, irrespective of the user's locale.</p>
1063
<p>If <i>ok</i> is not 0: if a conversion error occurs, *<i>ok</i>
1064
is set to false; otherwise *<i>ok</i> is set to true.</p>
1065
<p><b>Note:</b> The conversion of the number is performed in the
1066
default C locale, irrespective of the user's locale.</p>
511
1067
<p>See also <a href="qbytearray.html#number">number</a>().</p>
512
<a name="//apple_ref/cpp/instm/QByteArray/toUpper" />
513
<h3 class="fn"><a name="trimmed" /><a href="qbytearray.html">QByteArray</a> QByteArray.trimmed (<i>self</i>)</h3><p>Returns a byte array that has whitespace removed from the start and the end.</p>
514
<p>Whitespace means any character for which the standard C++ isspace() function returns true. This includes the ASCII characters '\t', '\n', '\v', '\f', '\r', and ' '.</p>
1070
<h3 class="fn"><a name="trimmed" /><a href="qbytearray.html">QByteArray</a> QByteArray.trimmed (<i>self</i>)</h3><p>Returns a byte array that has whitespace removed from the start
1072
<p>Whitespace means any character for which the standard C++
1073
isspace() function returns true. This includes the ASCII characters
1074
'\t', '\n', '\v', '\f', '\r', and ' '.</p>
516
<pre> QByteArray ba(" lots\t of\nwhitespace\r\n ");
1076
<pre class="highlightedCode brush: cpp">
1077
QByteArray ba(" lots\t of\nwhitespace\r\n ");
517
1078
ba = ba.trimmed();
518
<span class="comment"> // ba == "lots\t of\nwhitespace";</span></pre>
519
<p>Unlike <a href="qbytearray.html#simplified">simplified</a>(), trimmed() leaves internal whitespace alone.</p>
1079
<span class="comment"> // ba == "lots\t of\nwhitespace";</span>
1081
<p>Unlike <a href="qbytearray.html#simplified">simplified</a>(),
1082
trimmed() leaves internal whitespace alone.</p>
520
1083
<p>See also <a href="qbytearray.html#simplified">simplified</a>().</p>
521
<a name="//apple_ref/cpp/instm/QByteArray/truncate" />
522
1086
<h3 class="fn"><a name="truncate" />QByteArray.truncate (<i>self</i>, int)</h3><p>Truncates the byte array at index position <i>pos</i>.</p>
523
<p>If <i>pos</i> is beyond the end of the array, nothing happens.</p>
1087
<p>If <i>pos</i> is beyond the end of the array, nothing
525
<pre> QByteArray ba("Stockholm");
526
ba.truncate(5); <span class="comment">// ba == "Stock"</span></pre>
1090
<pre class="highlightedCode brush: cpp">
1091
QByteArray ba("Stockholm");
1092
ba.truncate(5); <span class="comment">// ba == "Stock"</span>
527
1094
<p>See also <a href="qbytearray.html#chop">chop</a>(), <a href="qbytearray.html#resize">resize</a>(), and <a href="qbytearray.html#left">left</a>().</p>
528
<a name="//apple_ref/cpp/instm/QByteArray/operator const char *" />
529
<h3 class="fn"><a name="__add__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__add__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__add__-2" />QString QByteArray.__add__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__contains__" />int QByteArray.__contains__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>a</i>)</h3><h3 class="fn"><a name="__eq__" />bool QByteArray.__eq__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__eq__-2" />bool QByteArray.__eq__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__ge__" />bool QByteArray.__ge__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__ge__-2" />bool QByteArray.__ge__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__getitem__" />str QByteArray.__getitem__ (<i>self</i>, int)</h3><h3 class="fn"><a name="__getitem__-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.__getitem__ (<i>self</i>, slice <i>slice</i>)</h3><h3 class="fn"><a name="__gt__" />bool QByteArray.__gt__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__gt__-2" />bool QByteArray.__gt__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__hash__" />int QByteArray.__hash__ (<i>self</i>)</h3><h3 class="fn"><a name="__iadd__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__iadd__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__iadd__-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.__iadd__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__imul__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__imul__ (<i>self</i>, int <i>m</i>)</h3><h3 class="fn"><a name="__le__" />bool QByteArray.__le__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__le__-2" />bool QByteArray.__le__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__len__" /> QByteArray.__len__ (<i>self</i>)</h3><h3 class="fn"><a name="__lt__" />bool QByteArray.__lt__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__lt__-2" />bool QByteArray.__lt__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__mul__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__mul__ (<i>self</i>, int <i>m</i>)</h3><h3 class="fn"><a name="__ne__" />bool QByteArray.__ne__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__ne__-2" />bool QByteArray.__ne__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__repr__" />str QByteArray.__repr__ (<i>self</i>)</h3><h3 class="fn"><a name="__str__" />str QByteArray.__str__ (<i>self</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.7.7 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.6.3</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'
1097
<h3 class="fn"><a name="__add__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__add__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__add__-2" />QString QByteArray.__add__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__contains__" />int QByteArray.__contains__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>a</i>)</h3><h3 class="fn"><a name="__eq__" />bool QByteArray.__eq__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__eq__-2" />bool QByteArray.__eq__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__ge__" />bool QByteArray.__ge__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__ge__-2" />bool QByteArray.__ge__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__getitem__" />str QByteArray.__getitem__ (<i>self</i>, int)</h3><h3 class="fn"><a name="__getitem__-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.__getitem__ (<i>self</i>, slice <i>slice</i>)</h3><h3 class="fn"><a name="__gt__" />bool QByteArray.__gt__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__gt__-2" />bool QByteArray.__gt__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__hash__" />int QByteArray.__hash__ (<i>self</i>)</h3><h3 class="fn"><a name="__iadd__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__iadd__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__iadd__-2" /><a href="qbytearray.html">QByteArray</a> QByteArray.__iadd__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__imul__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__imul__ (<i>self</i>, int <i>m</i>)</h3><h3 class="fn"><a name="__le__" />bool QByteArray.__le__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__le__-2" />bool QByteArray.__le__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__len__" /> QByteArray.__len__ (<i>self</i>)</h3><h3 class="fn"><a name="__lt__" />bool QByteArray.__lt__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__lt__-2" />bool QByteArray.__lt__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__mul__" /><a href="qbytearray.html">QByteArray</a> QByteArray.__mul__ (<i>self</i>, int <i>m</i>)</h3><h3 class="fn"><a name="__ne__" />bool QByteArray.__ne__ (<i>self</i>, QString)</h3><h3 class="fn"><a name="__ne__-2" />bool QByteArray.__ne__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a>)</h3><h3 class="fn"><a name="__repr__" />str QByteArray.__repr__ (<i>self</i>)</h3><h3 class="fn"><a name="__str__" />str QByteArray.__str__ (<i>self</i>)</h3><address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.8.1 for X11</td><td align="center" width="50%">Copyright © <a href="http://www.riverbankcomputing.com">Riverbank Computing Ltd</a> and <a href="http://www.qtsoftware.com">Nokia</a> 2010</td><td align="right" width="25%">Qt 4.7.0</td></tr></table></div></address></body></html>
b'\\ No newline at end of file'