Sophie

Sophie

distrib > Mageia > 7 > armv7hl > media > core-updates > by-pkgid > d5e62c01ae8d1e579463c6a871dd44bf > files > 317

qtbase5-doc-5.12.6-2.mga7.noarch.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- qbuffer.cpp -->
  <title>QBuffer Class | Qt Core 5.12.6</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td >Qt 5.12</td><td ><a href="qtcore-index.html">Qt Core</a></td><td ><a href="qtcore-module.html">C++ Classes</a></td><td >QBuffer</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtcore-index.html">Qt 5.12.6 Reference Documentation</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#public-functions">Public Functions</a></li>
<li class="level1"><a href="#reimplemented-public-functions">Reimplemented Public Functions</a></li>
<li class="level1"><a href="#static-public-members">Static Public Members</a></li>
<li class="level1"><a href="#reimplemented-protected-functions">Reimplemented Protected Functions</a></li>
<li class="level1"><a href="#details">Detailed Description</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">QBuffer Class</h1>
<!-- $$$QBuffer-brief -->
<p>The <a href="qbuffer.html">QBuffer</a> class provides a <a href="qiodevice.html">QIODevice</a> interface for a <a href="qbytearray.html">QByteArray</a>. <a href="#details">More...</a></p>
<!-- @@@QBuffer -->
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> Header:</td><td class="memItemRight bottomAlign">   <span class="preprocessor">#include &lt;QBuffer&gt;</span>
</td></tr><tr><td class="memItemLeft rightAlign topAlign"> qmake:</td><td class="memItemRight bottomAlign"> QT += core</td></tr><tr><td class="memItemLeft rightAlign topAlign"> Inherits:</td><td class="memItemRight bottomAlign"> <a href="qiodevice.html">QIODevice</a></td></tr></table></div><ul>
<li><a href="qbuffer-members.html">List of all members, including inherited members</a></li>
<li><a href="qbuffer-obsolete.html">Obsolete members</a></li>
</ul>
<p><b>Note:</b> All functions in this class are reentrant.</p>
<a name="public-functions"></a>
<h2 id="public-functions">Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#QBuffer">QBuffer</a></b>(QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#QBuffer-1">QBuffer</a></b>(QByteArray *<i>byteArray</i>, QObject *<i>parent</i> = nullptr)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#dtor.QBuffer">~QBuffer</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> QByteArray &amp;</td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#buffer">buffer</a></b>()</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QByteArray &amp;</td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#buffer-1">buffer</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> const QByteArray &amp;</td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#data">data</a></b>() const</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#setBuffer">setBuffer</a></b>(QByteArray *<i>byteArray</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#setData">setData</a></b>(const QByteArray &amp;<i>data</i>)</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> void </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#setData-1">setData</a></b>(const char *<i>data</i>, int <i>size</i>)</td></tr>
</table></div>
<a name="reimplemented-public-functions"></a>
<h2 id="reimplemented-public-functions">Reimplemented Public Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#atEnd">atEnd</a></b>() const override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#canReadLine">canReadLine</a></b>() const override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual void </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#close">close</a></b>() override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#open">open</a></b>(QIODevice::OpenMode <i>flags</i>) override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#pos">pos</a></b>() const override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual bool </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#seek">seek</a></b>(qint64 <i>pos</i>) override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#size">size</a></b>() const override</td></tr>
</table></div>
<ul>
<li class="fn">44 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
<li class="fn">32 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<a name="static-public-members"></a>
<h2 id="static-public-members">Static Public Members</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> const QMetaObject </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#staticMetaObject-var">staticMetaObject</a></b></td></tr>
</table></div>
<ul>
<li class="fn">10 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
</ul>
<a name="reimplemented-protected-functions"></a>
<h2 id="reimplemented-protected-functions">Reimplemented Protected Functions</h2>
<div class="table"><table class="alignedsummary">
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#readData">readData</a></b>(char *<i>data</i>, qint64 <i>len</i>) override</td></tr>
<tr><td class="memItemLeft rightAlign topAlign"> virtual qint64 </td><td class="memItemRight bottomAlign"><b><a href="qbuffer.html#writeData">writeData</a></b>(const char *<i>data</i>, qint64 <i>len</i>) override</td></tr>
</table></div>
<ul>
<li class="fn">5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
<li class="fn">9 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li class="fn">1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li class="fn">1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li class="fn">6 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
<li class="fn">2 signals inherited from <a href="qobject.html#signals">QObject</a></li>
<li class="fn">5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
<li class="fn">9 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<!-- $$$QBuffer-description -->
<div class="descr">
<h2 id="details">Detailed Description</h2>
<p>The <a href="qbuffer.html">QBuffer</a> class provides a <a href="qiodevice.html">QIODevice</a> interface for a <a href="qbytearray.html">QByteArray</a>.</p>
<p><a href="qbuffer.html">QBuffer</a> 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"><a href="qbuffer.html#QBuffer">QBuffer</a></span> buffer;
      <span class="type">char</span> ch;

      buffer<span class="operator">.</span>open(<span class="type"><a href="qbuffer.html#QBuffer">QBuffer</a></span><span class="operator">::</span>ReadWrite);
      buffer<span class="operator">.</span>write(<span class="string">&quot;Qt rocks!&quot;</span>);
      buffer<span class="operator">.</span>seek(<span class="number">0</span>);
      buffer<span class="operator">.</span>getChar(<span class="operator">&amp;</span>ch);  <span class="comment">// ch == 'Q'</span>
      buffer<span class="operator">.</span>getChar(<span class="operator">&amp;</span>ch);  <span class="comment">// ch == 't'</span>
      buffer<span class="operator">.</span>getChar(<span class="operator">&amp;</span>ch);  <span class="comment">// ch == ' '</span>
      buffer<span class="operator">.</span>getChar(<span class="operator">&amp;</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 <a href="qbuffer.html">QBuffer</a>. You can access this buffer directly by calling <a href="qbuffer.html#buffer">buffer</a>(). You can also use <a href="qbuffer.html">QBuffer</a> with an existing <a href="qbytearray.html">QByteArray</a> by calling <a href="qbuffer.html#setBuffer">setBuffer</a>(), or by passing your array to <a href="qbuffer.html">QBuffer</a>'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 <a href="qbuffer.html">QBuffer</a>:</p>
<pre class="cpp">

      <span class="type"><a href="qbytearray.html">QByteArray</a></span> byteArray;
      <span class="type"><a href="qbuffer.html#QBuffer">QBuffer</a></span> buffer(<span class="operator">&amp;</span>byteArray);
      buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html#QIODevice">QIODevice</a></span><span class="operator">::</span>WriteOnly);

      <span class="type"><a href="qdatastream.html">QDataStream</a></span> out(<span class="operator">&amp;</span>buffer);
      out <span class="operator">&lt;</span><span class="operator">&lt;</span> <span class="type"><a href="../qtwidgets/qapplication.html">QApplication</a></span><span class="operator">::</span>palette();

</pre>
<p>Effectively, we convert the application's <a href="../qtgui/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="../qtgui/qpalette.html">QPalette</a></span> palette;
      <span class="type"><a href="qbuffer.html#QBuffer">QBuffer</a></span> buffer(<span class="operator">&amp;</span>byteArray);
      buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html#QIODevice">QIODevice</a></span><span class="operator">::</span>ReadOnly);

      <span class="type"><a href="qdatastream.html">QDataStream</a></span> in(<span class="operator">&amp;</span>buffer);
      in <span class="operator">&gt;</span><span class="operator">&gt;</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 <a href="qbuffer.html">QBuffer</a> behind the scenes.</p>
<p><a href="qbuffer.html">QBuffer</a> emits <a href="qiodevice.html#readyRead">readyRead</a>() when new data has arrived in the buffer. By connecting to this signal, you can use <a href="qbuffer.html">QBuffer</a> to store temporary data before processing it. <a href="qbuffer.html">QBuffer</a> also emits <a href="qiodevice.html#bytesWritten">bytesWritten</a>() every time new data has been written to the buffer.</p>
</div>
<p><b>See also </b><a href="qfile.html">QFile</a>, <a href="qdatastream.html">QDataStream</a>, <a href="qtextstream.html">QTextStream</a>, and <a href="qbytearray.html">QByteArray</a>.</p>
<!-- @@@QBuffer -->
<div class="func">
<h2>Member Function Documentation</h2>
<!-- $$$QBuffer[overload1]$$$QBufferQObject* -->
<h3 class="fn" id="QBuffer"><a name="QBuffer"></a>QBuffer::<span class="name">QBuffer</span>(<span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<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>
<!-- @@@QBuffer -->
<!-- $$$QBuffer$$$QBufferQByteArray*QObject* -->
<h3 class="fn" id="QBuffer-1"><a name="QBuffer-1"></a>QBuffer::<span class="name">QBuffer</span>(<span class="type"><a href="qbytearray.html">QByteArray</a></span> *<i>byteArray</i>, <span class="type"><a href="qobject.html#QObject">QObject</a></span> *<i>parent</i> = nullptr)</h3>
<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">&quot;abc&quot;</span>);
      <span class="type"><a href="qbuffer.html#QBuffer">QBuffer</a></span> buffer(<span class="operator">&amp;</span>byteArray);
      buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html#QIODevice">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">&quot;def&quot;</span><span class="operator">,</span> <span class="number">3</span>);
      buffer<span class="operator">.</span>close();
      <span class="comment">// byteArray == &quot;abcdef&quot;</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>
<!-- @@@QBuffer -->
<!-- $$$~QBuffer[overload1]$$$~QBuffer -->
<h3 class="fn" id="dtor.QBuffer"><a name="dtor.QBuffer"></a><code>[virtual] </code>QBuffer::<span class="name">~QBuffer</span>()</h3>
<p>Destroys the buffer.</p>
<!-- @@@~QBuffer -->
<!-- $$$atEnd[overload1]$$$atEnd -->
<h3 class="fn" id="atEnd"><a name="atEnd"></a><code>[override virtual] </code><span class="type">bool</span> QBuffer::<span class="name">atEnd</span>() const</h3>
<p>Reimplemented from <a href="qiodevice.html#atEnd">QIODevice::atEnd</a>().</p>
<!-- @@@atEnd -->
<!-- $$$buffer[overload1]$$$buffer -->
<h3 class="fn" id="buffer"><a name="buffer"></a><span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;QBuffer::<span class="name">buffer</span>()</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>
<!-- @@@buffer -->
<!-- $$$buffer$$$buffer -->
<h3 class="fn" id="buffer-1"><a name="buffer-1"></a>const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;QBuffer::<span class="name">buffer</span>() const</h3>
<p>This is an overloaded function.</p>
<p>This is the same as <a href="qbuffer.html#data">data</a>().</p>
<!-- @@@buffer -->
<!-- $$$canReadLine[overload1]$$$canReadLine -->
<h3 class="fn" id="canReadLine"><a name="canReadLine"></a><code>[override virtual] </code><span class="type">bool</span> QBuffer::<span class="name">canReadLine</span>() const</h3>
<p>Reimplemented from <a href="qiodevice.html#canReadLine">QIODevice::canReadLine</a>().</p>
<!-- @@@canReadLine -->
<!-- $$$close[overload1]$$$close -->
<h3 class="fn" id="close"><a name="close"></a><code>[override virtual] </code><span class="type">void</span> QBuffer::<span class="name">close</span>()</h3>
<p>Reimplemented from <a href="qiodevice.html#close">QIODevice::close</a>().</p>
<!-- @@@close -->
<!-- $$$data[overload1]$$$data -->
<h3 class="fn" id="data"><a name="data"></a>const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;QBuffer::<span class="name">data</span>() const</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>
<!-- @@@data -->
<!-- $$$open[overload1]$$$openQIODevice::OpenMode -->
<h3 class="fn" id="open"><a name="open"></a><code>[override virtual] </code><span class="type">bool</span> QBuffer::<span class="name">open</span>(<span class="type"><a href="qiodevice.html#OpenModeFlag-enum">QIODevice::OpenMode</a></span> <i>flags</i>)</h3>
<p>Reimplemented from <a href="qiodevice.html#open">QIODevice::open</a>().</p>
<!-- @@@open -->
<!-- $$$pos[overload1]$$$pos -->
<h3 class="fn" id="pos"><a name="pos"></a><code>[override virtual] </code><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QBuffer::<span class="name">pos</span>() const</h3>
<p>Reimplemented from <a href="qiodevice.html#pos">QIODevice::pos</a>().</p>
<!-- @@@pos -->
<!-- $$$readData[overload1]$$$readDatachar*qint64 -->
<h3 class="fn" id="readData"><a name="readData"></a><code>[override virtual protected] </code><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QBuffer::<span class="name">readData</span>(<span class="type">char</span> *<i>data</i>, <span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>len</i>)</h3>
<p>Reimplemented from <a href="qiodevice.html#readData">QIODevice::readData</a>().</p>
<!-- @@@readData -->
<!-- $$$seek[overload1]$$$seekqint64 -->
<h3 class="fn" id="seek"><a name="seek"></a><code>[override virtual] </code><span class="type">bool</span> QBuffer::<span class="name">seek</span>(<span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>pos</i>)</h3>
<p>Reimplemented from <a href="qiodevice.html#seek">QIODevice::seek</a>().</p>
<!-- @@@seek -->
<!-- $$$setBuffer[overload1]$$$setBufferQByteArray* -->
<h3 class="fn" id="setBuffer"><a name="setBuffer"></a><span class="type">void</span> QBuffer::<span class="name">setBuffer</span>(<span class="type"><a href="qbytearray.html">QByteArray</a></span> *<i>byteArray</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">&quot;abc&quot;</span>);
      <span class="type"><a href="qbuffer.html#QBuffer">QBuffer</a></span> buffer;
      buffer<span class="operator">.</span>setBuffer(<span class="operator">&amp;</span>byteArray);
      buffer<span class="operator">.</span>open(<span class="type"><a href="qiodevice.html#QIODevice">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">&quot;def&quot;</span><span class="operator">,</span> <span class="number">3</span>);
      buffer<span class="operator">.</span>close();
      <span class="comment">// byteArray == &quot;abcdef&quot;</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>
<!-- @@@setBuffer -->
<!-- $$$setData[overload1]$$$setDataconstQByteArray& -->
<h3 class="fn" id="setData"><a name="setData"></a><span class="type">void</span> QBuffer::<span class="name">setData</span>(const <span class="type"><a href="qbytearray.html">QByteArray</a></span> &amp;<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>
<!-- @@@setData -->
<!-- $$$setData$$$setDataconstchar*int -->
<h3 class="fn" id="setData-1"><a name="setData-1"></a><span class="type">void</span> QBuffer::<span class="name">setData</span>(const <span class="type">char</span> *<i>data</i>, <span class="type">int</span> <i>size</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>
<!-- @@@setData -->
<!-- $$$size[overload1]$$$size -->
<h3 class="fn" id="size"><a name="size"></a><code>[override virtual] </code><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QBuffer::<span class="name">size</span>() const</h3>
<p>Reimplemented from <a href="qiodevice.html#size">QIODevice::size</a>().</p>
<!-- @@@size -->
<!-- $$$writeData[overload1]$$$writeDataconstchar*qint64 -->
<h3 class="fn" id="writeData"><a name="writeData"></a><code>[override virtual protected] </code><span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> QBuffer::<span class="name">writeData</span>(const <span class="type">char</span> *<i>data</i>, <span class="type"><a href="qtglobal.html#qint64-typedef">qint64</a></span> <i>len</i>)</h3>
<p>Reimplemented from <a href="qiodevice.html#writeData">QIODevice::writeData</a>().</p>
<!-- @@@writeData -->
</div>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>