QBuffer(3qt)
π QBuffer β the manual page, but make it make sense π
okay bestie, we're reading qbuffer.3qt together and honestly? it's giving iconic. it's a Qt 3 man page, section 3qt, and I'm gonna walk you through every single crumb of it. no skips. no cap. π
β¨ NAME β¨
QBuffer β an I/O device that operates on a QByteArray. that's it, that's the whole vibe. π
πΈ SYNOPSIS πΈ
first things first, the glow-up disclaimer:
All the functions in this class are reentrant when Qt is built with thread support.
yesss she's thread-safe (when you built Qt with thread support, obviously). π₯
and you gotta pull her in like this:
#include <qbuffer.h>
she Inherits QIODevice, so all that QIODevice energy is inherited, periodt.
π Public Members
QBuffer ()QBuffer ( QByteArray buf )~QBuffer ()QByteArray buffer () constbool setBuffer ( QByteArray buf )virtual Q_LONG writeBlock ( const char * p, Q_ULONG len )Q_LONG writeBlock ( const QByteArray & data )
π¦ DESCRIPTION π¦
so, the QBuffer class is an I/O device that operates on a QByteArray. main character behavior honestly.
QBuffer is used to read and write to a memory buffer. she's normally hanging out with a QTextStream or a QDataStream β that's her friend group. QBuffer has an associated QByteArray which holds the buffer data. and the size() of the buffer? it automatically adjusts as data is written. self-adjusting queen. β¨
the constructor QBuffer(QByteArray) creates a QBuffer using an existing byte array. you can also set the byte array with setBuffer(). and here's the tea: writing to the QBuffer will modify the original byte array because QByteArray is explicitly shared. it's giving "we're all connected" fr fr.
use open() to open the buffer before use and to set the mode (read-only, write-only, etc.). close() closes the buffer. and lowkey important: the buffer must be closed before reopening or calling setBuffer(). don't skip that step bestie, she will not be okay with it. π
a common way to use QBuffer is through QDataStream or QTextStream, which have constructors that take a QBuffer parameter. for convenience, there are also QDataStream and QTextStream constructors that take a QByteArray parameter. these constructors create and open an internal QBuffer. so convenient. obsessed. π«Ά
note that QTextStream can also operate on a QString (a Unicode string); a QBuffer cannot. just so we're clear on the boundaries. π
you can also use QBuffer directly through the standard QIODevice functions: readBlock(), writeBlock(), readLine(), at(), getch(), putch() and ungetch(). go off, queen. π
See also QFile, QDataStream, QTextStream, QByteArray, Shared Classes, Collection Classes, and Input/Output and Networking.
π MEMBER FUNCTION DOCUMENTATION π
π QBuffer::QBuffer ()
Constructs an empty buffer. that's it. a little empty baby buffer, ready to be filled with potential. π«
π QBuffer::QBuffer ( QByteArray buf )
Constructs a buffer that operates on buf.
if you open the buffer in write mode (IO_WriteOnly or IO_ReadWrite) and write something into the buffer, buf will be modified. it's giving consequences of your actions, bestie.
Example:
QCString str = "abc";
QBuffer b( str );
b.open( IO_WriteOnly );
b.at( 3 ); // position at the 4th character (the terminating \0)
b.writeBlock( "def", 4 ); // write "def" including the terminating \0
b.close();
// Now, str == "abcdef" with a terminating \0
See also setBuffer().
π QBuffer::~QBuffer ()
Destroys the buffer. RIP little buffer, you served. π (affectionate)
π QByteArray QBuffer::buffer () const
Returns this buffer's byte array. here's your data back, girl. π
See also setBuffer().
π bool QBuffer::setBuffer ( QByteArray buf )
Replaces the buffer's contents with buf and returns TRUE. slay.
does nothing (and returns FALSE) if isOpen() is TRUE. so if she's already open, she's not hearing it. π€
note that if you open the buffer in write mode (IO_WriteOnly or IO_ReadWrite) and write something into the buffer, buf is also modified because QByteArray is an explicitly shared class. the sharing is real and it's mutual.
See also buffer(), open(), and close().
π Q_LONG QBuffer::writeBlock ( const char * p, Q_ULONG len ) [virtual]
writes len bytes from p 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. she's flexible like that. π
returns -1 if an error occurred. an actual error. the bad kind. π
See also readBlock().
Reimplemented from QIODevice. iconic inheritance moment.
π Q_LONG QBuffer::writeBlock ( const QByteArray & data )
this is an overloaded member function, provided for convenience. it behaves essentially like the above function. same energy, different signature.
this convenience function is the same as calling writeBlock( data.data(), data.size() ) with data.
π₯ SEE ALSO π₯
πΈ COPYRIGHT πΈ
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement. legal girlies, this one's for you. π
β AUTHOR β
Generated automatically from the source code. no human author, just β¨ automation β¨.
π BUGS π
if you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. good bug reports help us to help you. Thank you. π«Ά (they said thank you and they meant it.)
the definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. this man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech. okay so it's the unofficial baddie of documentation formats, we move. π¦
if you find errors in this manual page, please report them to qt-bugs@trolltech.com. please include the name of the manual page (qbuffer.3qt) and the Qt version (3.3.8). receipts matter, bestie. π
and that's the whole page!! brought to you by Trolltech AS, dated 2 February 2007, from the QBuffer(3qt) man page, Qt version 3.3.8 β tysm for reading, ily, go open a buffer responsibly πβ¨πΈ
π¦ where this page comes from
- fedora 43: qt3-devel-docs 3.3.8b-102.fc43 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- fedora 44: qt3-devel-docs 3.3.8b-103.fc44 Β· QPL-1.0 OR GPL-2.0-only OR GPL-3.0-only
- Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms