Sophie

Sophie

distrib > CentOS > 5 > x86_64 > by-pkgid > ac91357d6caede925de099a02fced14e > files > 3808

qt4-doc-4.2.1-1.el5_7.1.x86_64.rpm

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /tmp/qt-4.2.1-harald-1161357942206/qt-x11-opensource-src-4.2.1/src/corelib/io/qbuffer.cpp -->
<head>
  <title>Qt 4.2: QBuffer Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></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>
<pre> #include &lt;QBuffer&gt;</pre><p>Inherits <a href="qiodevice.html">QIODevice</a>.</p>
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
<ul>
<li><a href="qbuffer-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qbuffer.html#QBuffer">QBuffer</a></b> ( QObject * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qbuffer.html#QBuffer-2">QBuffer</a></b> ( QByteArray * <i>byteArray</i>, QObject * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qbuffer.html#dtor.QBuffer">~QBuffer</a></b> ()</li>
<li><div class="fn"/>QByteArray &amp; <b><a href="qbuffer.html#buffer">buffer</a></b> ()</li>
<li><div class="fn"/>const QByteArray &amp; <b><a href="qbuffer.html#buffer-2">buffer</a></b> () const</li>
<li><div class="fn"/>const QByteArray &amp; <b><a href="qbuffer.html#data">data</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qbuffer.html#setBuffer">setBuffer</a></b> ( QByteArray * <i>byteArray</i> )</li>
<li><div class="fn"/>void <b><a href="qbuffer.html#setData">setData</a></b> ( const QByteArray &amp; <i>data</i> )</li>
<li><div class="fn"/>void <b><a href="qbuffer.html#setData-2">setData</a></b> ( const char * <i>data</i>, int <i>size</i> )</li>
</ul>
<ul>
<li><div class="fn"/>32 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"/>3 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"/>5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
</ul>
<a name="details"></a>
<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>     QBuffer buffer;
     char ch;

     buffer.open(QBuffer::ReadWrite);
     buffer.write(&quot;Qt rocks!&quot;);
     buffer.seek(0);
     buffer.getChar(&amp;ch);  <span class="comment">// ch == 'Q'</span>
     buffer.getChar(&amp;ch);  <span class="comment">// ch == 't'</span>
     buffer.getChar(&amp;ch);  <span class="comment">// ch == ' '</span>
     buffer.getChar(&amp;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="qiodevice.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="qiodevice.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="qiodevice.html#seek">seek</a>(). When you are done with accessing the buffer, call <a href="qiodevice.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>     QByteArray byteArray;
     QBuffer buffer(&amp;byteArray);
     buffer.open(QIODevice::WriteOnly);

     QDataStream out(&amp;buffer);
     out &lt;&lt; QApplication::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>     QPalette palette;
     QBuffer buffer(&amp;byteArray);
     buffer.open(QIODevice::ReadOnly);

     QDataStream in(&amp;buffer);
     in &gt;&gt; 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>
<p>See also <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>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QBuffer"></a>QBuffer::QBuffer ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</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>See also <a href="qiodevice.html#open">open</a>().</p>
<h3 class="fn"><a name="QBuffer-2"></a>QBuffer::QBuffer ( <a href="qbytearray.html">QByteArray</a> * <i>byteArray</i>, <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</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>     QByteArray byteArray(&quot;abc&quot;);
     QBuffer buffer(&amp;byteArray);
     buffer.open(QIODevice::WriteOnly);
     buffer.seek(3);
     buffer.write(&quot;def&quot;, 3);
     buffer.close();
     <span class="comment">// byteArray == &quot;abcdef&quot;</span></pre>
<p>See also <a href="qiodevice.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="dtor.QBuffer"></a>QBuffer::~QBuffer ()</h3>
<p>Destroys the buffer.</p>
<h3 class="fn"><a name="buffer"></a><a href="qbytearray.html">QByteArray</a> &amp; QBuffer::buffer ()</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>See also <a href="qbuffer.html#setBuffer">setBuffer</a>() and <a href="qbuffer.html#data">data</a>().</p>
<h3 class="fn"><a name="buffer-2"></a>const <a href="qbytearray.html">QByteArray</a> &amp; QBuffer::buffer () const</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<h3 class="fn"><a name="data"></a>const <a href="qbytearray.html">QByteArray</a> &amp; QBuffer::data () 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>See also <a href="qbuffer.html#setData">setData</a>() and <a href="qbuffer.html#setBuffer">setBuffer</a>().</p>
<h3 class="fn"><a name="setBuffer"></a>void QBuffer::setBuffer ( <a href="qbytearray.html">QByteArray</a> * <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>     QByteArray byteArray(&quot;abc&quot;);
     QBuffer buffer;
     buffer.setBuffer(&amp;byteArray);
     buffer.open(QIODevice::WriteOnly);
     buffer.seek(3);
     buffer.write(&quot;def&quot;, 3);
     buffer.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>See also <a href="qbuffer.html#buffer">buffer</a>(), <a href="qbuffer.html#setData">setData</a>(), and <a href="qiodevice.html#open">open</a>().</p>
<h3 class="fn"><a name="setData"></a>void QBuffer::setData ( const <a href="qbytearray.html">QByteArray</a> &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>See also <a href="qbuffer.html#data">data</a>() and <a href="qbuffer.html#setBuffer">setBuffer</a>().</p>
<h3 class="fn"><a name="setData-2"></a>void QBuffer::setData ( const char * <i>data</i>, int <i>size</i> )</h3>
<p>This is an overloaded member function, provided for convenience.</p>
<p>Sets the contents of the internal buffer to be the first <i>size</i> bytes of <i>data</i>.</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2006 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.2.1</div></td>
</tr></table></div></address></body>
</html>