summaryrefslogtreecommitdiffstats
path: root/doc/html/qbuffer.html
blob: 9c98c9c9692c8f79fcbdf97d8fd124497c2d8810 (plain)
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qbuffer.cpp:41 -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>QBuffer Class</title>
<style type="text/css"><!--
fn { margin-left: 1cm; text-indent: -1cm; }
a:link { color: #004faf; text-decoration: none }
a:visited { color: #672967; text-decoration: none }
body { background: #ffffff; color: black; }
--></style>
</head>
<body>

<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr bgcolor="#E5E5E5">
<td valign=center>
 <a href="index.html">
<font color="#004faf">Home</font></a>
 | <a href="classes.html">
<font color="#004faf">All&nbsp;Classes</font></a>
 | <a href="mainclasses.html">
<font color="#004faf">Main&nbsp;Classes</font></a>
 | <a href="annotated.html">
<font color="#004faf">Annotated</font></a>
 | <a href="groups.html">
<font color="#004faf">Grouped&nbsp;Classes</font></a>
 | <a href="functions.html">
<font color="#004faf">Functions</font></a>
</td>
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QBuffer Class Reference</h1>

<p>The QBuffer class is an I/O device that operates on a QByteArray.
<a href="#details">More...</a>
<p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
<p><tt>#include &lt;<a href="qbuffer-h.html">qbuffer.h</a>&gt;</tt>
<p>Inherits <a href="qiodevice.html">QIODevice</a>.
<p><a href="qbuffer-members.html">List of all member functions.</a>
<h2>Public Members</h2>
<ul>
<li class=fn><a href="#QBuffer"><b>QBuffer</b></a> ()</li>
<li class=fn><a href="#QBuffer-2"><b>QBuffer</b></a> ( QByteArray&nbsp;buf )</li>
<li class=fn><a href="#~QBuffer"><b>~QBuffer</b></a> ()</li>
<li class=fn>QByteArray <a href="#buffer"><b>buffer</b></a> () const</li>
<li class=fn>bool <a href="#setBuffer"><b>setBuffer</b></a> ( QByteArray&nbsp;buf )</li>
<li class=fn>virtual Q_LONG <a href="#writeBlock"><b>writeBlock</b></a> ( const&nbsp;char&nbsp;*&nbsp;p, Q_ULONG&nbsp;len )</li>
<li class=fn>Q_LONG <a href="#writeBlock-2"><b>writeBlock</b></a> ( const&nbsp;QByteArray&nbsp;&amp;&nbsp;data )</li>
</ul>
<hr><a name="details"></a><h2>Detailed Description</h2>



The QBuffer class is an I/O device that operates on a <a href="qbytearray.html">QByteArray</a>.
<p> 

<p> QBuffer is used to read and write to a memory buffer. It is
normally used with a <a href="qtextstream.html">QTextStream</a> or a <a href="qdatastream.html">QDataStream</a>. QBuffer has an
associated QByteArray which holds the buffer data. The <a href="qiodevice.html#size">size</a>() of
the buffer is automatically adjusted as data is written.
<p> The constructor <tt>QBuffer(QByteArray)</tt> creates a QBuffer using an
existing byte array. The byte array can also be set with
<a href="#setBuffer">setBuffer</a>(). Writing to the QBuffer will modify the original byte
array because QByteArray is <a href="shclass.html">explicitly
    shared.</a>
<p> Use <a href="qiodevice.html#open">open</a>() to open the buffer before use and to set the mode
(read-only, write-only, etc.). <a href="qiodevice.html#close">close</a>() closes the buffer. The
buffer must be closed before reopening or calling setBuffer().
<p> A common way to use QBuffer is through <a href="qdatastream.html">QDataStream</a> or <a href="qtextstream.html">QTextStream</a>, which have constructors that take a QBuffer
parameter. For convenience, there are also QDataStream and
<a href="qtextstream.html">QTextStream</a> constructors that take a <a href="qbytearray.html">QByteArray</a> parameter. These
constructors create and open an internal QBuffer.
<p> Note that QTextStream can also operate on a <a href="qstring.html">QString</a> (a Unicode
string); a QBuffer cannot.
<p> You can also use QBuffer directly through the standard <a href="qiodevice.html">QIODevice</a>
functions <a href="qiodevice.html#readBlock">readBlock</a>(), <a href="#writeBlock">writeBlock</a>() <a href="qiodevice.html#readLine">readLine</a>(), <a href="qiodevice.html#at">at</a>(), <a href="qiodevice.html#getch">getch</a>(),
<a href="qiodevice.html#putch">putch</a>() and <a href="qiodevice.html#ungetch">ungetch</a>().
<p> <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>, <a href="shclass.html">Shared Classes</a>, <a href="collection.html">Collection Classes</a>, and <a href="io.html">Input/Output and Networking</a>.

<hr><h2>Member Function Documentation</h2>
<h3 class=fn><a name="QBuffer"></a>QBuffer::QBuffer ()
</h3>
Constructs an empty buffer.

<h3 class=fn><a name="QBuffer-2"></a>QBuffer::QBuffer ( <a href="qbytearray.html">QByteArray</a>&nbsp;buf )
</h3>
Constructs a buffer that operates on <em>buf</em>.
<p> If you open the buffer in write mode (<a href="qfile.html#open"><a href="qfile.html#open">IO_WriteOnly</a></a> or
<a href="qfile.html#open">IO_ReadWrite</a>) and write something into the buffer, <em>buf</em>
will be modified.
<p> Example:
<pre>
    <a href="qcstring.html">QCString</a> str = "abc";
    QBuffer b( str );
    b.<a href="qiodevice.html#open">open</a>( IO_WriteOnly );
    b.<a href="qiodevice.html#at">at</a>( 3 ); // position at the 4th character (the terminating \0)
    b.<a href="#writeBlock">writeBlock</a>( "def", 4 ); // write "def" including the terminating \0
    b.<a href="qiodevice.html#close">close</a>();
    // Now, str == "abcdef" with a terminating \0
    </pre>
 
<p> <p>See also <a href="#setBuffer">setBuffer</a>().

<h3 class=fn><a name="~QBuffer"></a>QBuffer::~QBuffer ()
</h3>
Destroys the buffer.

<h3 class=fn><a href="qbytearray.html">QByteArray</a> <a name="buffer"></a>QBuffer::buffer () const
</h3>

<p> Returns this buffer's byte array.
<p> <p>See also <a href="#setBuffer">setBuffer</a>().

<h3 class=fn>bool <a name="setBuffer"></a>QBuffer::setBuffer ( <a href="qbytearray.html">QByteArray</a>&nbsp;buf )
</h3>
Replaces the buffer's contents with <em>buf</em> and returns TRUE.
<p> Does nothing (and returns FALSE) if <a href="qiodevice.html#isOpen">isOpen</a>() is TRUE.
<p> Note that if you open the buffer in write mode (<a href="qfile.html#open"><a href="qfile.html#open">IO_WriteOnly</a></a> or
<a href="qfile.html#open">IO_ReadWrite</a>) and write something into the buffer, <em>buf</em> is also
modified because <a href="qbytearray.html">QByteArray</a> is an <a href="shclass.html#explicitly-shared">explicitly shared</a> class.
<p> <p>See also <a href="#buffer">buffer</a>(), <a href="qiodevice.html#open">open</a>(), and <a href="qiodevice.html#close">close</a>().

<h3 class=fn>Q_LONG <a name="writeBlock"></a>QBuffer::writeBlock ( const&nbsp;char&nbsp;*&nbsp;p, Q_ULONG&nbsp;len )<tt> [virtual]</tt>
</h3>
Writes <em>len</em> bytes from <em>p</em> into the buffer at the current
index position, overwriting any characters there and extending the
buffer if necessary. Returns the number of bytes actually written.
<p> Returns -1 if an error occurred.
<p> <p>See also <a href="qiodevice.html#readBlock">readBlock</a>().

<p>Reimplemented from <a href="qiodevice.html#writeBlock">QIODevice</a>.
<h3 class=fn>Q_LONG <a name="writeBlock-2"></a>QBuffer::writeBlock ( const&nbsp;<a href="qbytearray.html">QByteArray</a>&nbsp;&amp;&nbsp;data )
</h3>
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
<p> This convenience function is the same as calling
<tt>writeBlock( data.data(), data.size() )</tt> with <em>data</em>.

<!-- eof -->
<hr><p>
This file is part of the <a href="index.html">Qt toolkit</a>.
Copyright &copy; 1995-2007
<a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
<table width=100% cellspacing=0 border=0><tr>
<td>Copyright &copy; 2007
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
<td align=right><div align=right>Qt 3.3.8</div>
</table></div></address></body>
</html>