Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QBuffer Class

The QBuffer class provides a QIODevice interface for a QByteArray. More...

 #include <QBuffer>

Inherits: QIODevice.

Note: All functions in this class are reentrant.

Public Types

flags OpenMode
enum OpenModeFlag { NotOpen, ReadOnly, WriteOnly, ReadWrite, ..., Unbuffered }

Public Functions

QBuffer(QObject * parent = 0)
QBuffer(QByteArray * byteArray, QObject * parent = 0)
QIODevice()
QIODevice(QObject * parent)
~QBuffer()
virtual ~QIODevice()
virtual bool atEnd() const
QByteArray & buffer()
const QByteArray & buffer() const
virtual qint64 bytesAvailable() const
virtual qint64 bytesToWrite() const
virtual bool canReadLine() const
virtual void close()
const QByteArray & data() const
QString errorString() const
bool getChar(char * c)
bool isOpen() const
bool isReadable() const
virtual bool isSequential() const
bool isTextModeEnabled() const
bool isWritable() const
virtual bool open(OpenMode mode)
OpenMode openMode() const
qint64 peek(char * data, qint64 maxSize)
QByteArray peek(qint64 maxSize)
virtual qint64 pos() const
bool putChar(char c)
qint64 read(char * data, qint64 maxSize)
QByteArray read(qint64 maxSize)
QByteArray readAll()
qint64 readLine(char * data, qint64 maxSize)
QByteArray readLine(qint64 maxSize = 0)
virtual bool reset()
virtual bool seek(qint64 pos)
void setBuffer(QByteArray * byteArray)
void setData(const QByteArray & data)
void setData(const char * data, int size)
void setTextModeEnabled(bool enabled)
virtual qint64 size() const
void ungetChar(char c)
virtual bool waitForBytesWritten(int msecs)
virtual bool waitForReadyRead(int msecs)
qint64 write(const char * data, qint64 maxSize)
qint64 write(const char * data)
qint64 write(const QByteArray & byteArray)

Reimplemented Public Functions

virtual bool atEnd() const
virtual bool canReadLine() const
virtual void close()
virtual bool open(OpenMode flags)
virtual qint64 pos() const
virtual bool seek(qint64 pos)
virtual qint64 size() const
  • 31 public functions inherited from QObject

Signals

void aboutToClose()
void bytesWritten(qint64 bytes)
void readChannelFinished()
void readyRead()

Protected Functions

virtual qint64 readData(char * data, qint64 maxSize) = 0
virtual qint64 readLineData(char * data, qint64 maxSize)
void setErrorString(const QString & str)
void setOpenMode(OpenMode openMode)
virtual qint64 writeData(const char * data, qint64 maxSize) = 0

Reimplemented Protected Functions

virtual qint64 readData(char * data, qint64 len)
virtual qint64 writeData(const char * data, qint64 len)
  • 9 protected functions inherited from QObject

Additional Inherited Members

  • 1 property inherited from QObject
  • 1 public slot inherited from QObject
  • 11 static public members inherited from QObject

Detailed Description

The QBuffer class provides a QIODevice interface for a QByteArray.

QBuffer allows you to access a QByteArray using the QIODevice interface. The QByteArray is treated just as a standard random-accessed file. Example:

     QBuffer buffer;
     char ch;

     buffer.open(QBuffer::ReadWrite);
     buffer.write("Qt rocks!");
     buffer.seek(0);
     buffer.getChar(&ch);  // ch == 'Q'
     buffer.getChar(&ch);  // ch == 't'
     buffer.getChar(&ch);  // ch == ' '
     buffer.getChar(&ch);  // ch == 'r'

By default, an internal QByteArray buffer is created for you when you create a QBuffer. You can access this buffer directly by calling buffer(). You can also use QBuffer with an existing QByteArray by calling setBuffer(), or by passing your array to QBuffer's constructor.

Call open() to open the buffer. Then call write() or putChar() to write to the buffer, and read(), readLine(), readAll(), or getChar() to read from it. size() returns the current size of the buffer, and you can seek to arbitrary positions in the buffer by calling seek(). When you are done with accessing the buffer, call close().

The following code snippet shows how to write data to a QByteArray using QDataStream and QBuffer:

     QByteArray byteArray;
     QBuffer buffer(&byteArray);
     buffer.open(QIODevice::WriteOnly);

     QDataStream out(&buffer);
     out << QApplication::palette();

Effectively, we convert the application's QPalette into a byte array. Here's how to read the data from the QByteArray:

     QPalette palette;
     QBuffer buffer(&byteArray);
     buffer.open(QIODevice::ReadOnly);

     QDataStream in(&buffer);
     in >> palette;

QTextStream and QDataStream also provide convenience constructors that take a QByteArray and that create a QBuffer behind the scenes.

QBuffer emits readyRead() when new data has arrived in the buffer. By connecting to this signal, you can use QBuffer to store temporary data before processing it. QBuffer also emits bytesWritten() every time new data has been written to the buffer.

See also QFile, QDataStream, QTextStream, and QByteArray.

Member Function Documentation

QBuffer::QBuffer(QObject * parent = 0)

Constructs an empty buffer with the given parent. You can call setData() to fill the buffer with data, or you can open it in write mode and use write().

See also open().

QBuffer::QBuffer(QByteArray * byteArray, QObject * parent = 0)

Constructs a QBuffer that uses the QByteArray pointed to by byteArray as its internal buffer, and with the given parent. The caller is responsible for ensuring that byteArray remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer doesn't take ownership of the QByteArray.

If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, byteArray will be modified.

Example:

     QByteArray byteArray("abc");
     QBuffer buffer(&byteArray);
     buffer.open(QIODevice::WriteOnly);
     buffer.seek(3);
     buffer.write("def", 3);
     buffer.close();
     // byteArray == "abcdef"

See also open(), setBuffer(), and setData().

QBuffer::~QBuffer()

Destroys the buffer.

bool QBuffer::atEnd() const [virtual]

Reimplemented from QIODevice::atEnd().

QByteArray & QBuffer::buffer()

Returns a reference to the QBuffer's internal buffer. You can use it to modify the QByteArray behind the QBuffer's back.

See also setBuffer() and data().

const QByteArray & QBuffer::buffer() const

This is an overloaded function.

This is the same as data().

bool QBuffer::canReadLine() const [virtual]

Reimplemented from QIODevice::canReadLine().

void QBuffer::close() [virtual]

Reimplemented from QIODevice::close().

const QByteArray & QBuffer::data() const

Returns the data contained in the buffer.

This is the same as buffer().

See also setData() and setBuffer().

bool QBuffer::open(OpenMode flags) [virtual]

Reimplemented from QIODevice::open().

qint64 QBuffer::pos() const [virtual]

Reimplemented from QIODevice::pos().

qint64 QBuffer::readData(char * data, qint64 len) [virtual protected]

Reimplemented from QIODevice::readData().

bool QBuffer::seek(qint64 pos) [virtual]

Reimplemented from QIODevice::seek().

void QBuffer::setBuffer(QByteArray * byteArray)

Makes QBuffer uses the QByteArray pointed to by byteArray as its internal buffer. The caller is responsible for ensuring that byteArray remains valid until the QBuffer is destroyed, or until setBuffer() is called to change the buffer. QBuffer doesn't take ownership of the QByteArray.

Does nothing if isOpen() is true.

If you open the buffer in write-only mode or read-write mode and write something into the QBuffer, byteArray will be modified.

Example:

     QByteArray byteArray("abc");
     QBuffer buffer;
     buffer.setBuffer(&byteArray);
     buffer.open(QIODevice::WriteOnly);
     buffer.seek(3);
     buffer.write("def", 3);
     buffer.close();
     // byteArray == "abcdef"

If byteArray is 0, the buffer creates its own internal QByteArray to work on. This byte array is initially empty.

See also buffer(), setData(), and open().

void QBuffer::setData(const QByteArray & data)

Sets the contents of the internal buffer to be data. This is the same as assigning data to buffer().

Does nothing if isOpen() is true.

See also data() and setBuffer().

void QBuffer::setData(const char * data, int size)

This is an overloaded function.

Sets the contents of the internal buffer to be the first size bytes of data.

qint64 QBuffer::size() const [virtual]

Reimplemented from QIODevice::size().

qint64 QBuffer::writeData(const char * data, qint64 len) [virtual protected]

Reimplemented from QIODevice::writeData().

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 5.0-snapshot
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web