[Go]-Qbuffer class reference

Source: Internet
Author: User

Qbuffer class Reference

The Qbuffer class is an input/output device that operates Qbytearray. For details, please see ...

#include <qbuffer.h>

Inherited the Qiodevice.

A list of all member functions.

Public members
    • Qbuffer ()
    • Qbuffer (Qbytearray buf)
    • ~qbuffer ()
    • Qbytearray Buffer () const
    • BOOL setbuffer (Qbytearray buf)
    • Virtual Q_long writeblock (const char * p, Q_ulong len)
    • Q_long writeblock (const Qbytearray & Data)

Detailed description

The Qbuffer class is an input/output device that operates Qbytearray.

Qbuffer is used to read and write memory caches. It is usually used in conjunction with Qtextstream or Qdatastream. The Qbuffer has an associated qbytearray to store buffered data. The buffer size (size ()) is automatically adjusted according to the data being written.

The constructor Qbuffer (Qbytearray) creates a qbuffer with an existing byte array. Byte arrays can also be set by SetBuffer (). Writing to Qbuffer will change the initial byte array, because Qbytearray is explicitly shared.

Use open () to turn on the cache and set the mode (read only, write-only, and so on) before use. Close () to turn off caching. The cache must be closed before re-opening or calling SetBuffer ().

A common way to use Qbuffer is through Qdatastream or qtextstream, which can be constructed with a qbuffer parameter. For convenience, Qdatastream and Qtextstream can also be constructed using a Qbytearray parameter. These constructors create and open an internal qbuffer.

Note Qtextstream can also manipulate qstring (a Unicode string), and Qbuffer cannot.

You can also use Getch directly from the standard Qiodevice functions Readblock (), WriteBlock (), ReadLine (), at (), Putch (), Ungetch (), and Qbuffer ().

You can also refer to Qfile, Qdatastream, Qtextstream, Qbytearray, shared classes, collection classes, and input/output and networks.

member function document Qbuffer::qbuffer ()

Constructs an empty cache.

Qbuffer::qbuffer (Qbytearray buf)

Manipulate buf to construct a cache. If you use write mode (io_writeonly or Io_readwrite) to open the cache and write something to the cache,buf will be modified.

Instance:

    qcstring str = "abc";    Qbuffer b (str);    B.open (io_writeonly);    b.at (3); Navigate to the fourth character (Terminator)    B.writeblock ("Def", 4);//write "Def", including Terminator    B.close ();    Now, str is "abcdef" and a terminator.  

You can also refer to SetBuffer ().

Qbuffer::~qbuffer ()

The destructor cache.

Qbytearray Qbuffer::buffer () const

Returns the byte array for this cache.

You can also refer to a href= "#setBuffer" >setbuffer ().

BOOL Qbuffer::setbuffer (Qbytearray buf)

Replace the cached content with buf.

When IsOpen () is true, this operation may not be completed.

Note If you use write mode (io_writeonly or Io_readwrite) to open the cache and write something to the cache,buf will also be modified because Qbytearray is an obvious shared class.

You can also refer to buffer (), open (), and Close ().

Q_long qbuffer::writeblock (const char * p, Q_ulong len)[Virtual]

Writes the len byte in p to the current index of the cache, overwriting the original data and expanding the cache if necessary. Returns the actual number of bytes written.

If any errors occur, return-1.

You can also join the card Readblock ().

Reimplemented from Qiodevice.

Q_long qbuffer::writeblock (const Qbytearray & Data)

This is an overloaded member function that provides convenience. Its behavior is basically the same as the above function.

This handy function uses data to be the same as calling WriteBlock (Data.data (), Data.size ()).

[Go]-Qbuffer class reference

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.