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  ·  Fonctions  · 

QBuffer Class Reference

The QBuffer class is an I/O device that operates on a QByteArray. More...

All the functions in this class are reentrant when Qt is built with thread support.

#include <qbuffer.h>

Inherits QIODevice.

List of all member functions.

Public Members


Detailed Description

The QBuffer class is an I/O device that operates on a QByteArray.

QBuffer is used to read and write to a memory buffer. It is normally used with a QTextStream or a QDataStream. QBuffer has an associated QByteArray which holds the buffer data. The size() of the buffer is automatically adjusted as data is written.

The constructor QBuffer(QByteArray) creates a QBuffer using an existing byte array. The byte array can also be set with setBuffer(). Writing to the QBuffer will modify the original byte array because QByteArray is explicitly shared.

Use open() to open the buffer before use and to set the mode (read-only, write-only, etc.). close() closes the buffer. The buffer must be closed before reopening or calling setBuffer().

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.

Note that QTextStream can also operate on a QString (a Unicode string); a QBuffer cannot.

You can also use QBuffer directly through the standard QIODevice functions readBlock(), writeBlock() readLine(), at(), getch(), putch() and ungetch().

See also QFile, QDataStream, QTextStream, QByteArray, Shared Classes, Collection Classes, and Input/Output and Networking.


Member Function Documentation

QBuffer::QBuffer ()

Constructs an empty buffer.

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.

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.

QByteArray QBuffer::buffer () const

Returns this buffer's byte array.

See also setBuffer().

bool QBuffer::setBuffer ( QByteArray buf )

Replaces the buffer's contents with buf and returns TRUE.

Does nothing (and returns FALSE) if isOpen() is TRUE.

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.

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.

Returns -1 if an error occurred.

See also readBlock().

Reimplemented from QIODevice.

Q_LONG QBuffer::writeBlock ( const QByteArray & data )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This convenience function is the same as calling writeBlock( data.data(), data.size() ) with data.


This file is part of the Qt toolkit. Copyright © 1995-2005 Trolltech. All Rights Reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  4. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 41
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 6
Page suivante

Le Qt Labs au hasard

Logo

Améliorer les performances de Qt lors du rendu avec plus de SIMD

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

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 3.3
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