1 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
---|
2 | <!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/src/tools/qbuffer.cpp:41 -->
|
---|
3 | <html>
|
---|
4 | <head>
|
---|
5 | <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
---|
6 | <title>QBuffer Class</title>
|
---|
7 | <style type="text/css"><!--
|
---|
8 | fn { margin-left: 1cm; text-indent: -1cm; }
|
---|
9 | a:link { color: #004faf; text-decoration: none }
|
---|
10 | a:visited { color: #672967; text-decoration: none }
|
---|
11 | body { background: #ffffff; color: black; }
|
---|
12 | --></style>
|
---|
13 | </head>
|
---|
14 | <body>
|
---|
15 |
|
---|
16 | <table border="0" cellpadding="0" cellspacing="0" width="100%">
|
---|
17 | <tr bgcolor="#E5E5E5">
|
---|
18 | <td valign=center>
|
---|
19 | <a href="index.html">
|
---|
20 | <font color="#004faf">Home</font></a>
|
---|
21 | | <a href="classes.html">
|
---|
22 | <font color="#004faf">All Classes</font></a>
|
---|
23 | | <a href="mainclasses.html">
|
---|
24 | <font color="#004faf">Main Classes</font></a>
|
---|
25 | | <a href="annotated.html">
|
---|
26 | <font color="#004faf">Annotated</font></a>
|
---|
27 | | <a href="groups.html">
|
---|
28 | <font color="#004faf">Grouped Classes</font></a>
|
---|
29 | | <a href="functions.html">
|
---|
30 | <font color="#004faf">Functions</font></a>
|
---|
31 | </td>
|
---|
32 | <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>
|
---|
33 |
|
---|
34 | <p>The QBuffer class is an I/O device that operates on a QByteArray.
|
---|
35 | <a href="#details">More...</a>
|
---|
36 | <p>All the functions in this class are <a href="threads.html#reentrant">reentrant</a> when Qt is built with thread support.</p>
|
---|
37 | <p><tt>#include <<a href="qbuffer-h.html">qbuffer.h</a>></tt>
|
---|
38 | <p>Inherits <a href="qiodevice.html">QIODevice</a>.
|
---|
39 | <p><a href="qbuffer-members.html">List of all member functions.</a>
|
---|
40 | <h2>Public Members</h2>
|
---|
41 | <ul>
|
---|
42 | <li class=fn><a href="#QBuffer"><b>QBuffer</b></a> ()</li>
|
---|
43 | <li class=fn><a href="#QBuffer-2"><b>QBuffer</b></a> ( QByteArray buf )</li>
|
---|
44 | <li class=fn><a href="#~QBuffer"><b>~QBuffer</b></a> ()</li>
|
---|
45 | <li class=fn>QByteArray <a href="#buffer"><b>buffer</b></a> () const</li>
|
---|
46 | <li class=fn>bool <a href="#setBuffer"><b>setBuffer</b></a> ( QByteArray buf )</li>
|
---|
47 | <li class=fn>virtual Q_LONG <a href="#writeBlock"><b>writeBlock</b></a> ( const char * p, Q_ULONG len )</li>
|
---|
48 | <li class=fn>Q_LONG <a href="#writeBlock-2"><b>writeBlock</b></a> ( const QByteArray & data )</li>
|
---|
49 | </ul>
|
---|
50 | <hr><a name="details"></a><h2>Detailed Description</h2>
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | The QBuffer class is an I/O device that operates on a <a href="qbytearray.html">QByteArray</a>.
|
---|
55 | <p>
|
---|
56 |
|
---|
57 | <p> QBuffer is used to read and write to a memory buffer. It is
|
---|
58 | normally used with a <a href="qtextstream.html">QTextStream</a> or a <a href="qdatastream.html">QDataStream</a>. QBuffer has an
|
---|
59 | associated QByteArray which holds the buffer data. The <a href="qiodevice.html#size">size</a>() of
|
---|
60 | the buffer is automatically adjusted as data is written.
|
---|
61 | <p> The constructor <tt>QBuffer(QByteArray)</tt> creates a QBuffer using an
|
---|
62 | existing byte array. The byte array can also be set with
|
---|
63 | <a href="#setBuffer">setBuffer</a>(). Writing to the QBuffer will modify the original byte
|
---|
64 | array because QByteArray is <a href="shclass.html">explicitly
|
---|
65 | shared.</a>
|
---|
66 | <p> Use <a href="qiodevice.html#open">open</a>() to open the buffer before use and to set the mode
|
---|
67 | (read-only, write-only, etc.). <a href="qiodevice.html#close">close</a>() closes the buffer. The
|
---|
68 | buffer must be closed before reopening or calling setBuffer().
|
---|
69 | <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
|
---|
70 | parameter. For convenience, there are also QDataStream and
|
---|
71 | <a href="qtextstream.html">QTextStream</a> constructors that take a <a href="qbytearray.html">QByteArray</a> parameter. These
|
---|
72 | constructors create and open an internal QBuffer.
|
---|
73 | <p> Note that QTextStream can also operate on a <a href="qstring.html">QString</a> (a Unicode
|
---|
74 | string); a QBuffer cannot.
|
---|
75 | <p> You can also use QBuffer directly through the standard <a href="qiodevice.html">QIODevice</a>
|
---|
76 | 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>(),
|
---|
77 | <a href="qiodevice.html#putch">putch</a>() and <a href="qiodevice.html#ungetch">ungetch</a>().
|
---|
78 | <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>.
|
---|
79 |
|
---|
80 | <hr><h2>Member Function Documentation</h2>
|
---|
81 | <h3 class=fn><a name="QBuffer"></a>QBuffer::QBuffer ()
|
---|
82 | </h3>
|
---|
83 | Constructs an empty buffer.
|
---|
84 |
|
---|
85 | <h3 class=fn><a name="QBuffer-2"></a>QBuffer::QBuffer ( <a href="qbytearray.html">QByteArray</a> buf )
|
---|
86 | </h3>
|
---|
87 | Constructs a buffer that operates on <em>buf</em>.
|
---|
88 | <p> If you open the buffer in write mode (<a href="qfile.html#open"><a href="qfile.html#open">IO_WriteOnly</a></a> or
|
---|
89 | <a href="qfile.html#open">IO_ReadWrite</a>) and write something into the buffer, <em>buf</em>
|
---|
90 | will be modified.
|
---|
91 | <p> Example:
|
---|
92 | <pre>
|
---|
93 | <a href="qcstring.html">QCString</a> str = "abc";
|
---|
94 | QBuffer b( str );
|
---|
95 | b.<a href="qiodevice.html#open">open</a>( IO_WriteOnly );
|
---|
96 | b.<a href="qiodevice.html#at">at</a>( 3 ); // position at the 4th character (the terminating \0)
|
---|
97 | b.<a href="#writeBlock">writeBlock</a>( "def", 4 ); // write "def" including the terminating \0
|
---|
98 | b.<a href="qiodevice.html#close">close</a>();
|
---|
99 | // Now, str == "abcdef" with a terminating \0
|
---|
100 | </pre>
|
---|
101 |
|
---|
102 | <p> <p>See also <a href="#setBuffer">setBuffer</a>().
|
---|
103 |
|
---|
104 | <h3 class=fn><a name="~QBuffer"></a>QBuffer::~QBuffer ()
|
---|
105 | </h3>
|
---|
106 | Destroys the buffer.
|
---|
107 |
|
---|
108 | <h3 class=fn><a href="qbytearray.html">QByteArray</a> <a name="buffer"></a>QBuffer::buffer () const
|
---|
109 | </h3>
|
---|
110 |
|
---|
111 | <p> Returns this buffer's byte array.
|
---|
112 | <p> <p>See also <a href="#setBuffer">setBuffer</a>().
|
---|
113 |
|
---|
114 | <h3 class=fn>bool <a name="setBuffer"></a>QBuffer::setBuffer ( <a href="qbytearray.html">QByteArray</a> buf )
|
---|
115 | </h3>
|
---|
116 | Replaces the buffer's contents with <em>buf</em> and returns TRUE.
|
---|
117 | <p> Does nothing (and returns FALSE) if <a href="qiodevice.html#isOpen">isOpen</a>() is TRUE.
|
---|
118 | <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
|
---|
119 | <a href="qfile.html#open">IO_ReadWrite</a>) and write something into the buffer, <em>buf</em> is also
|
---|
120 | modified because <a href="qbytearray.html">QByteArray</a> is an <a href="shclass.html#explicitly-shared">explicitly shared</a> class.
|
---|
121 | <p> <p>See also <a href="#buffer">buffer</a>(), <a href="qiodevice.html#open">open</a>(), and <a href="qiodevice.html#close">close</a>().
|
---|
122 |
|
---|
123 | <h3 class=fn>Q_LONG <a name="writeBlock"></a>QBuffer::writeBlock ( const char * p, Q_ULONG len )<tt> [virtual]</tt>
|
---|
124 | </h3>
|
---|
125 | Writes <em>len</em> bytes from <em>p</em> into the buffer at the current
|
---|
126 | index position, overwriting any characters there and extending the
|
---|
127 | buffer if necessary. Returns the number of bytes actually written.
|
---|
128 | <p> Returns -1 if an error occurred.
|
---|
129 | <p> <p>See also <a href="qiodevice.html#readBlock">readBlock</a>().
|
---|
130 |
|
---|
131 | <p>Reimplemented from <a href="qiodevice.html#writeBlock">QIODevice</a>.
|
---|
132 | <h3 class=fn>Q_LONG <a name="writeBlock-2"></a>QBuffer::writeBlock ( const <a href="qbytearray.html">QByteArray</a> & data )
|
---|
133 | </h3>
|
---|
134 | This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
|
---|
135 | <p> This convenience function is the same as calling
|
---|
136 | <tt>writeBlock( data.data(), data.size() )</tt> with <em>data</em>.
|
---|
137 |
|
---|
138 | <!-- eof -->
|
---|
139 | <hr><p>
|
---|
140 | This file is part of the <a href="index.html">Qt toolkit</a>.
|
---|
141 | Copyright © 1995-2007
|
---|
142 | <a href="http://www.trolltech.com/">Trolltech</a>. All Rights Reserved.<p><address><hr><div align=center>
|
---|
143 | <table width=100% cellspacing=0 border=0><tr>
|
---|
144 | <td>Copyright © 2007
|
---|
145 | <a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
---|
146 | <td align=right><div align=right>Qt 3.3.8</div>
|
---|
147 | </table></div></address></body>
|
---|
148 | </html>
|
---|