1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html><head><title>QBuffer Class Reference</title><style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
td.postheader { font-family: sans-serif }
tr.address { font-family: sans-serif }
body { background: #ffffff; color: black; }
</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="index.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">QBuffer Class Reference<br /><sup><sup>[<a href="qtcore.html">QtCore</a> module]</sup></sup></h1><p>The QBuffer class provides a <a href="qiodevice.html">QIODevice</a> interface for a <a href="qbytearray.html">QByteArray</a>. <a href="#details">More...</a></p>
<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p><h3>Methods</h3><ul><li><div class="fn" /><b><a href="qbuffer.html#QBuffer">__init__</a></b> (<i>self</i>, QObject <i>parent</i> = None)</li><li><div class="fn" /><b><a href="qbuffer.html#QBuffer-2">__init__</a></b> (<i>self</i>, QByteArray <i>byteArray</i>, QObject <i>parent</i> = None)</li><li><div class="fn" />bool <b><a href="qbuffer.html#atEnd">atEnd</a></b> (<i>self</i>)</li><li><div class="fn" />QByteArray <b><a href="qbuffer.html#buffer">buffer</a></b> (<i>self</i>)</li><li><div class="fn" />bool <b><a href="qbuffer.html#canReadLine">canReadLine</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qbuffer.html#close">close</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qbuffer.html#connectNotify">connectNotify</a></b> (<i>self</i>, object)</li><li><div class="fn" />QByteArray <b><a href="qbuffer.html#data">data</a></b> (<i>self</i>)</li><li><div class="fn" /><b><a href="qbuffer.html#disconnectNotify">disconnectNotify</a></b> (<i>self</i>, object)</li><li><div class="fn" />bool <b><a href="qbuffer.html#open">open</a></b> (<i>self</i>, QIODevice.OpenMode <i>openMode</i>)</li><li><div class="fn" />int <b><a href="qbuffer.html#pos">pos</a></b> (<i>self</i>)</li><li><div class="fn" />object <b><a href="qbuffer.html#readData">readData</a></b> (<i>self</i>, int <i>maxlen</i>)</li><li><div class="fn" />bool <b><a href="qbuffer.html#seek">seek</a></b> (<i>self</i>, int <i>off</i>)</li><li><div class="fn" /><b><a href="qbuffer.html#setBuffer">setBuffer</a></b> (<i>self</i>, QByteArray <i>a</i>)</li><li><div class="fn" /><b><a href="qbuffer.html#setData">setData</a></b> (<i>self</i>, QByteArray <i>data</i>)</li><li><div class="fn" /><b><a href="qbuffer.html#setData-2">setData</a></b> (<i>self</i>, bytes <i>adata</i>)</li><li><div class="fn" />int <b><a href="qbuffer.html#size">size</a></b> (<i>self</i>)</li><li><div class="fn" />int <b><a href="qbuffer.html#writeData">writeData</a></b> (<i>self</i>, bytes <i>data</i>)</li></ul><a name="details" /><hr /><h2>Detailed Description</h2><p>The QBuffer class provides a <a href="qiodevice.html">QIODevice</a> interface for a <a href="qbytearray.html">QByteArray</a>.</p>
<p>QBuffer allows you to access a <a href="qbytearray.html">QByteArray</a> using the <a href="qiodevice.html">QIODevice</a> interface. The <a href="qbytearray.html">QByteArray</a> is treated just as a standard
random-accessed file. Example:</p>
<pre class="cpp">
<span class="type">QBuffer</span> buffer;
<span class="type">char</span> ch;
buffer<span class="operator">.</span>open(<span class="type">QBuffer</span><span class="operator">.</span>ReadWrite);
buffer<span class="operator">.</span>write(<span class="string">"Qt rocks!"</span>);
buffer<span class="operator">.</span>seek(<span class="number">0</span>);
buffer<span class="operator">.</span>getChar(<span class="operator">&</span>ch); <span class="comment">// ch == 'Q'</span>
buffer<span class="operator">.</span>getChar(<span class="operator">&</span>ch); <span class="comment">// ch == 't'</span>
buffer<span class="operator">.</span>getChar(<span class="operator">&</span>ch); <span class="comment">// ch == ' '</span>
buffer<span class="operator">.</span>getChar(<span class="operator">&</span>ch); <span class="comment">// ch == 'r'</span>
</pre>
<p>By default, an internal <a href="qbytearray.html">QByteArray</a>
buffer is created for you when you create a QBuffer. You can access
this buffer directly by calling <a href="qbuffer.html#buffer">buffer</a>(). You can also use QBuffer with
an existing <a href="qbytearray.html">QByteArray</a> by calling
<a href="qbuffer.html#setBuffer">setBuffer</a>(), or by passing
your array to QBuffer's constructor.</p>
<p>Call <a href="qbuffer.html#open">open</a>() to open the buffer.
Then call <a href="qiodevice.html#write">write</a>() or <a href="qiodevice.html#putChar">putChar</a>() to write to the buffer, and
<a href="qiodevice.html#read">read</a>(), <a href="qiodevice.html#readLine">readLine</a>(), <a href="qiodevice.html#readAll">readAll</a>(), or <a href="qiodevice.html#getChar">getChar</a>() to read from it. <a href="qbuffer.html#size">size</a>() returns the current size of the
buffer, and you can seek to arbitrary positions in the buffer by
calling <a href="qbuffer.html#seek">seek</a>(). When you are done
with accessing the buffer, call <a href="qbuffer.html#close">close</a>().</p>
<p>The following code snippet shows how to write data to a <a href="qbytearray.html">QByteArray</a> using <a href="qdatastream.html">QDataStream</a> and QBuffer:</p>
<pre class="cpp">
<span class="type"><a href="qbytearray.html">QByteArray</a></span> byteArray;
<span class="type">QBuffer</span> buffer(<span class="operator">&</span>byteArray);
buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>WriteOnly);
<span class="type"><a href="qdatastream.html">QDataStream</a></span> out(<span class="operator">&</span>buffer);
out <span class="operator"><</span><span class="operator"><</span> <span class="type"><a href="qapplication.html">QApplication</a></span><span class="operator">.</span>palette();
</pre>
<p>Effectively, we convert the application's <a href="qpalette.html">QPalette</a> into a byte array. Here's how to read
the data from the <a href="qbytearray.html">QByteArray</a>:</p>
<pre class="cpp">
<span class="type"><a href="qpalette.html">QPalette</a></span> palette;
<span class="type">QBuffer</span> buffer(<span class="operator">&</span>byteArray);
buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>ReadOnly);
<span class="type"><a href="qdatastream.html">QDataStream</a></span> in(<span class="operator">&</span>buffer);
in <span class="operator">></span><span class="operator">></span> palette;
</pre>
<p><a href="qtextstream.html">QTextStream</a> and <a href="qdatastream.html">QDataStream</a> also provide convenience
constructors that take a <a href="qbytearray.html">QByteArray</a>
and that create a QBuffer behind the scenes.</p>
<p>QBuffer emits <a href="qiodevice.html#readyRead">readyRead</a>()
when new data has arrived in the buffer. By connecting to this
signal, you can use QBuffer to store temporary data before
processing it. For example, you can pass the buffer to <a href="qftp.html">QFtp</a> when downloading a file from an FTP server.
Whenever a new payload of data has been downloaded, <a href="qiodevice.html#readyRead">readyRead</a>() is emitted, and you can
process the data that just arrived. QBuffer also emits <a href="qiodevice.html#bytesWritten">bytesWritten</a>() every time new
data has been written to the buffer.</p>
<hr /><h2>Method Documentation</h2><h3 class="fn"><a name="QBuffer" />QBuffer.__init__ (<i>self</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs an empty buffer with the given <i>parent</i>. You can
call <a href="qbuffer.html#setData">setData</a>() to fill the
buffer with data, or you can open it in write mode and use <a href="qiodevice.html#write">write</a>().</p>
<p><b>See also</b> <a href="qbuffer.html#open">open</a>().</p>
<h3 class="fn"><a name="QBuffer-2" />QBuffer.__init__ (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>byteArray</i>, <a href="qobject.html">QObject</a> <i>parent</i> = None)</h3><p>The <i>parent</i> argument, if not None, causes <i>self</i> to be owned by Qt instead of PyQt.</p><p>Constructs a <a href="qbuffer.html">QBuffer</a> that uses the
<a href="qbytearray.html">QByteArray</a> pointed to by
<i>byteArray</i> as its internal buffer, and with the given
<i>parent</i>. The caller is responsible for ensuring that
<i>byteArray</i> remains valid until the <a href="qbuffer.html">QBuffer</a> is destroyed, or until <a href="qbuffer.html#setBuffer">setBuffer</a>() is called to change the
buffer. <a href="qbuffer.html">QBuffer</a> doesn't take ownership
of the <a href="qbytearray.html">QByteArray</a>.</p>
<p>If you open the buffer in write-only mode or read-write mode and
write something into the <a href="qbuffer.html">QBuffer</a>,
<i>byteArray</i> will be modified.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qbytearray.html">QByteArray</a></span> byteArray(<span class="string">"abc"</span>);
<span class="type"><a href="qbuffer.html">QBuffer</a></span> buffer(<span class="operator">&</span>byteArray);
buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>WriteOnly);
buffer<span class="operator">.</span>seek(<span class="number">3</span>);
buffer<span class="operator">.</span>write(<span class="string">"def"</span><span class="operator">,</span> <span class="number">3</span>);
buffer<span class="operator">.</span>close();
<span class="comment">// byteArray == "abcdef"</span>
</pre>
<p><b>See also</b> <a href="qbuffer.html#open">open</a>(), <a href="qbuffer.html#setBuffer">setBuffer</a>(), and <a href="qbuffer.html#setData">setData</a>().</p>
<h3 class="fn"><a name="atEnd" />bool QBuffer.atEnd (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#atEnd">QIODevice.atEnd</a>().</p>
<h3 class="fn"><a name="buffer" /><a href="qbytearray.html">QByteArray</a> QBuffer.buffer (<i>self</i>)</h3><p>Returns a reference to the <a href="qbuffer.html">QBuffer</a>'s
internal buffer. You can use it to modify the <a href="qbytearray.html">QByteArray</a> behind the <a href="qbuffer.html">QBuffer</a>'s back.</p>
<p><b>See also</b> <a href="qbuffer.html#setBuffer">setBuffer</a>()
and <a href="qbuffer.html#data">data</a>().</p>
<h3 class="fn"><a name="canReadLine" />bool QBuffer.canReadLine (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#canReadLine">QIODevice.canReadLine</a>().</p>
<h3 class="fn"><a name="close" />QBuffer.close (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#close">QIODevice.close</a>().</p>
<h3 class="fn"><a name="connectNotify" />QBuffer.connectNotify (<i>self</i>, object)</h3><h3 class="fn"><a name="data" /><a href="qbytearray.html">QByteArray</a> QBuffer.data (<i>self</i>)</h3><p>Returns the data contained in the buffer.</p>
<p>This is the same as <a href="qbuffer.html#buffer">buffer</a>().</p>
<p><b>See also</b> <a href="qbuffer.html#setData">setData</a>() and
<a href="qbuffer.html#setBuffer">setBuffer</a>().</p>
<h3 class="fn"><a name="disconnectNotify" />QBuffer.disconnectNotify (<i>self</i>, object)</h3><h3 class="fn"><a name="open" />bool QBuffer.open (<i>self</i>, <a href="qiodevice-openmode.html">QIODevice.OpenMode</a> <i>openMode</i>)</h3><p>Reimplemented from <a href="qiodevice.html#open">QIODevice.open</a>().</p>
<h3 class="fn"><a name="pos" />int QBuffer.pos (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#pos">QIODevice.pos</a>().</p>
<h3 class="fn"><a name="readData" />object QBuffer.readData (<i>self</i>, int <i>maxlen</i>)</h3><p>Reimplemented from <a href="qiodevice.html#readData">QIODevice.readData</a>().</p>
<h3 class="fn"><a name="seek" />bool QBuffer.seek (<i>self</i>, int <i>off</i>)</h3><p>Reimplemented from <a href="qiodevice.html#seek">QIODevice.seek</a>().</p>
<h3 class="fn"><a name="setBuffer" />QBuffer.setBuffer (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>a</i>)</h3><p>Makes <a href="qbuffer.html">QBuffer</a> uses the <a href="qbytearray.html">QByteArray</a> pointed to by <i>byteArray</i> as
its internal buffer. The caller is responsible for ensuring that
<i>byteArray</i> remains valid until the <a href="qbuffer.html">QBuffer</a> is destroyed, or until setBuffer() is
called to change the buffer. <a href="qbuffer.html">QBuffer</a>
doesn't take ownership of the <a href="qbytearray.html">QByteArray</a>.</p>
<p>Does nothing if <a href="qiodevice.html#isOpen">isOpen</a>() is
true.</p>
<p>If you open the buffer in write-only mode or read-write mode and
write something into the <a href="qbuffer.html">QBuffer</a>,
<i>byteArray</i> will be modified.</p>
<p>Example:</p>
<pre class="cpp">
<span class="type"><a href="qbytearray.html">QByteArray</a></span> byteArray(<span class="string">"abc"</span>);
<span class="type"><a href="qbuffer.html">QBuffer</a></span> buffer;
buffer<span class="operator">.</span>setBuffer(<span class="operator">&</span>byteArray);
buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html">QIODevice</a></span><span class="operator">.</span>WriteOnly);
buffer<span class="operator">.</span>seek(<span class="number">3</span>);
buffer<span class="operator">.</span>write(<span class="string">"def"</span><span class="operator">,</span> <span class="number">3</span>);
buffer<span class="operator">.</span>close();
<span class="comment">// byteArray == "abcdef"</span>
</pre>
<p>If <i>byteArray</i> is 0, the buffer creates its own internal
<a href="qbytearray.html">QByteArray</a> to work on. This byte
array is initially empty.</p>
<p><b>See also</b> <a href="qbuffer.html#buffer">buffer</a>(),
<a href="qbuffer.html#setData">setData</a>(), and <a href="qbuffer.html#open">open</a>().</p>
<h3 class="fn"><a name="setData" />QBuffer.setData (<i>self</i>, <a href="qbytearray.html">QByteArray</a> <i>data</i>)</h3><p>Sets the contents of the internal buffer to be <i>data</i>. This
is the same as assigning <i>data</i> to <a href="qbuffer.html#buffer">buffer</a>().</p>
<p>Does nothing if <a href="qiodevice.html#isOpen">isOpen</a>() is
true.</p>
<p><b>See also</b> <a href="qbuffer.html#data">data</a>() and
<a href="qbuffer.html#setBuffer">setBuffer</a>().</p>
<h3 class="fn"><a name="setData-2" />QBuffer.setData (<i>self</i>, bytes <i>adata</i>)</h3><p>This is an overloaded function.</p>
<p>Sets the contents of the internal buffer to be the first
<i>size</i> bytes of <i>data</i>.</p>
<h3 class="fn"><a name="size" />int QBuffer.size (<i>self</i>)</h3><p>Reimplemented from <a href="qiodevice.html#size">QIODevice.size</a>().</p>
<h3 class="fn"><a name="writeData" />int QBuffer.writeData (<i>self</i>, bytes <i>data</i>)</h3><p>Reimplemented from <a href="qiodevice.html#writeData">QIODevice.writeData</a>().</p>
<address><hr /><div align="center"><table border="0" cellspacing="0" width="100%"><tr class="address"><td align="left" width="25%">PyQt 4.12.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.qt.io">The Qt Company</a> 2015</td><td align="right" width="25%">Qt 4.8.7</td></tr></table></div></address></body></html>
|