~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to doc/html/qbuffer.html

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="iso-8859-1"?>
 
2
<!DOCTYPE html
 
3
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
 
4
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
5
<!-- /tmp/qt-4.0.0-espenr-1119621036935/qt-x11-opensource-desktop-4.0.0/src/corelib/io/qbuffer.cpp -->
 
6
<head>
 
7
    <title>Qt 4.0: QBuffer Class Reference</title>
 
8
    <style>h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }
 
9
a:link { color: #004faf; text-decoration: none }
 
10
a:visited { color: #672967; text-decoration: none }
 
11
td.postheader { font-family: sans-serif }
 
12
tr.address { font-family: sans-serif }
 
13
body { background: #ffffff; color: black; }</style>
 
14
</head>
 
15
<body>
 
16
<table border="0" cellpadding="0" cellspacing="0" width="100%">
 
17
<tr>
 
18
<td align="left" valign="top" width="32"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></td>
 
19
<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="annotated.html"><font color="#004faf">Annotated</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
 
20
<td align="right" valign="top" width="230"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></td></tr></table><h1 align="center">QBuffer Class Reference</h1>
 
21
<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>
 
22
<pre>#include &lt;QBuffer&gt;</pre><p>Part of the <a href="qtcore.html">QtCore</a> module.</p>
 
23
<p>Inherits <a href="qiodevice.html">QIODevice</a>.</p>
 
24
<p><b>Note:</b> All the functions in this class are <a href="threads.html#reentrant">reentrant</a>.</p>
 
25
<ul>
 
26
<li><a href="qbuffer-members.html">List of all members, including inherited members</a></li>
 
27
</ul>
 
28
<a name="public-functions"></a>
 
29
<h3>Public Functions</h3>
 
30
<ul>
 
31
<li><div class="fn"/><b><a href="qbuffer.html#QBuffer">QBuffer</a></b> ( QObject * <i>parent</i> = 0 )</li>
 
32
<li><div class="fn"/><b><a href="qbuffer.html#QBuffer-2">QBuffer</a></b> ( QByteArray * <i>byteArray</i>, QObject * <i>parent</i> = 0 )</li>
 
33
<li><div class="fn"/><b><a href="qbuffer.html#dtor.QBuffer">~QBuffer</a></b> ()</li>
 
34
<li><div class="fn"/>QByteArray &amp; <b><a href="qbuffer.html#buffer">buffer</a></b> ()</li>
 
35
<li><div class="fn"/>const QByteArray &amp; <b><a href="qbuffer.html#buffer-2">buffer</a></b> () const</li>
 
36
<li><div class="fn"/>const QByteArray &amp; <b><a href="qbuffer.html#data">data</a></b> () const</li>
 
37
<li><div class="fn"/>void <b><a href="qbuffer.html#setBuffer">setBuffer</a></b> ( QByteArray * <i>byteArray</i> )</li>
 
38
<li><div class="fn"/>void <b><a href="qbuffer.html#setData">setData</a></b> ( const QByteArray &amp; <i>data</i> )</li>
 
39
<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>
 
40
</ul>
 
41
<ul>
 
42
<li><div class="fn"/>30 public functions inherited from <a href="qiodevice.html#public-functions">QIODevice</a></li>
 
43
<li><div class="fn"/>28 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
 
44
</ul>
 
45
<h3>Additional Inherited Members</h3>
 
46
<ul>
 
47
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
 
48
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
 
49
<li><div class="fn"/>3 signals inherited from <a href="qiodevice.html#signals">QIODevice</a></li>
 
50
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
 
51
<li><div class="fn"/>4 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
 
52
<li><div class="fn"/>5 protected functions inherited from <a href="qiodevice.html#protected-functions">QIODevice</a></li>
 
53
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
 
54
</ul>
 
55
<a name="details"></a>
 
56
<hr />
 
57
<h2>Detailed Description</h2>
 
58
<p>The QBuffer class provides a <a href="qiodevice.html">QIODevice</a> interface for a <a href="qbytearray.html">QByteArray</a>.</p>
 
59
<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>
 
60
<pre>&nbsp;       QBuffer buffer;
 
61
        char ch;
 
62
 
 
63
        buffer.open(QBuffer::ReadWrite);
 
64
        buffer.write(&quot;Qt rocks!&quot;);
 
65
        buffer.seek(0);
 
66
        buffer.getChar(&amp;ch);  // ch == 'Q'
 
67
        buffer.getChar(&amp;ch);  // ch == 't'
 
68
        buffer.getChar(&amp;ch);  // ch == ' '
 
69
        buffer.getChar(&amp;ch);  // ch == 'r'</pre>
 
70
<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>
 
71
<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>
 
72
<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>
 
73
<pre>&nbsp;       QByteArray byteArray;
 
74
        QBuffer buffer(&amp;byteArray);
 
75
        buffer.open(QIODevice::WriteOnly);
 
76
 
 
77
        QDataStream out(&amp;buffer);
 
78
        out &lt;&lt; QApplication::palette();</pre>
 
79
<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>
 
80
<pre>&nbsp;       QPalette palette;
 
81
        QBuffer buffer(&amp;byteArray);
 
82
        buffer.open(QIODevice::ReadOnly);
 
83
 
 
84
        QDataStream in(&amp;buffer);
 
85
        in &gt;&gt; palette;</pre>
 
86
<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>
 
87
<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>
 
88
<p>See also <a href="qfile.html">QFile</a>, <a href="qdatastream.html">QDataStream</a>, <a href="qtextstream.html">QTextStream</a>, <a href="qbytearray.html">QByteArray</a>, and <a href="shclass.html">Shared Classes</a>.</p>
 
89
<hr />
 
90
<h2>Member Function Documentation</h2>
 
91
<h3 class="fn"><a name="QBuffer"></a>QBuffer::QBuffer ( <a href="qobject.html">QObject</a> * <i>parent</i> = 0 )</h3>
 
92
<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>
 
93
<p>See also <a href="qbuffer.html#open">open</a>().</p>
 
94
<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>
 
95
<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>
 
96
<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>
 
97
<p>Example:</p>
 
98
<pre>&nbsp;       QByteArray byteArray(&quot;abc&quot;);
 
99
        QBuffer buffer(&amp;byteArray);
 
100
        buffer.open(QIODevice::WriteOnly);
 
101
        buffer.seek(3);
 
102
        buffer.write(&quot;def&quot;, 3);
 
103
        buffer.close();
 
104
        // byteArray == &quot;abcdef&quot;</pre>
 
105
<p>See also <a href="qbuffer.html#open">open</a>(), <a href="qbuffer.html#setBuffer">setBuffer</a>(), and <a href="qbuffer.html#setData">setData</a>().</p>
 
106
<h3 class="fn"><a name="dtor.QBuffer"></a>QBuffer::~QBuffer ()</h3>
 
107
<p>Destroys the buffer.</p>
 
108
<h3 class="fn"><a name="buffer"></a><a href="qbytearray.html">QByteArray</a> &amp; QBuffer::buffer ()</h3>
 
109
<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>
 
110
<p>See also <a href="qbuffer.html#setBuffer">setBuffer</a>() and <a href="qbuffer.html#data">data</a>().</p>
 
111
<h3 class="fn"><a name="buffer-2"></a>const <a href="qbytearray.html">QByteArray</a> &amp; QBuffer::buffer () const</h3>
 
112
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
113
<h3 class="fn"><a name="data"></a>const <a href="qbytearray.html">QByteArray</a> &amp; QBuffer::data () const</h3>
 
114
<p>Returns the data contained in the buffer.</p>
 
115
<p>This is the same as <a href="qbuffer.html#buffer">buffer</a>().</p>
 
116
<p>See also <a href="qbuffer.html#setData">setData</a>() and <a href="qbuffer.html#setBuffer">setBuffer</a>().</p>
 
117
<h3 class="fn"><a name="setBuffer"></a>void QBuffer::setBuffer ( <a href="qbytearray.html">QByteArray</a> * <i>byteArray</i> )</h3>
 
118
<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>
 
119
<p>Does nothing if <a href="qiodevice.html#isOpen">isOpen</a>() is true.</p>
 
120
<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>
 
121
<p>Example:</p>
 
122
<pre>&nbsp;       QByteArray byteArray(&quot;abc&quot;);
 
123
        QBuffer buffer;
 
124
        buffer.setBuffer(&amp;byteArray);
 
125
        buffer.open(QIODevice::WriteOnly);
 
126
        buffer.seek(3);
 
127
        buffer.write(&quot;def&quot;, 3);
 
128
        buffer.close();
 
129
        // byteArray == &quot;abcdef&quot;</pre>
 
130
<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>
 
131
<p>See also <a href="qbuffer.html#buffer">buffer</a>(), <a href="qbuffer.html#setData">setData</a>(), and <a href="qbuffer.html#open">open</a>().</p>
 
132
<h3 class="fn"><a name="setData"></a>void QBuffer::setData ( const <a href="qbytearray.html">QByteArray</a> &amp; <i>data</i> )</h3>
 
133
<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>
 
134
<p>Does nothing if <a href="qiodevice.html#isOpen">isOpen</a>() is true.</p>
 
135
<p>See also <a href="qbuffer.html#setBuffer">setBuffer</a>().</p>
 
136
<h3 class="fn"><a name="setData-2"></a>void QBuffer::setData ( const char * <i>data</i>, int <i>size</i> )</h3>
 
137
<p>This is an overloaded member function, provided for convenience. It behaves essentially like the above function.</p>
 
138
<p>Sets the contents of the internal buffer to be the first <i>size</i> bytes of <i>data</i>.</p>
 
139
<p /><address><hr /><div align="center">
 
140
<table width="100%" cellspacing="0" border="0"><tr class="address">
 
141
<td width="30%">Copyright &copy; 2005 <a href="trolltech.html">Trolltech</a></td>
 
142
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
 
143
<td width="30%" align="right"><div align="right">Qt 4.0.0</div></td>
 
144
</tr></table></div></address></body>
 
145
</html>