QBuffer 类提供 QIODevice 接口为 QByteArray . 更多...
继承 QIODevice .
QBuffer 类提供 QIODevice 接口为 QByteArray .
QBuffer 允许访问 QByteArray 使用 QIODevice 接口。 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'
默认情况下,内部 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 通过调用 setBuffer (), or by passing your array to QBuffer's constructor.
调用 open () to open the buffer. Then call write () 或 putChar () to write to the buffer, and read (), readLine (), readAll (),或 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 ().
下列代码片段展示如何把数据写入 QByteArray 使用 QDataStream 和 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 发射 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. For example, you can pass the buffer to QFtp when downloading a file from an FTP server. Whenever a new payload of data has been downloaded, readyRead () is emitted, and you can process the data that just arrived. QBuffer also emits bytesWritten () every time new data has been written to the buffer.
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
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 ().
另请参阅 open ().
parent argument, if not None, causes self to be owned by Qt instead of PyQt.
构造 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 的 QByteArray .
If you open the buffer in write-only mode or read-write mode and write something into the QBuffer , byteArray will be modified.
范例:
QByteArray byteArray("abc");
QBuffer buffer(&byteArray);
buffer.open(QIODevice.WriteOnly);
buffer.seek(3);
buffer.write("def", 3);
buffer.close();
// byteArray == "abcdef"
另请参阅 open (), setBuffer (),和 setData ().
重实现自 QIODevice.atEnd ().
Returns a reference to the QBuffer 's internal buffer. You can use it to modify the QByteArray behind the QBuffer 's back.
另请参阅 setBuffer () and data ().
重实现自 QIODevice.canReadLine ().
重实现自 QIODevice.close ().
返回包含在缓冲中的数据。
这如同 buffer ().
另请参阅 setData () 和 setBuffer ().
重实现自 QIODevice.open ().
重实现自 QIODevice.pos ().
重实现自 QIODevice.readData ().
重实现自 QIODevice.seek ().
Makes QBuffer 使用 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 .
什么都不做若 isOpen () 是 true.
If you open the buffer in write-only mode or read-write mode and write something into the QBuffer , byteArray will be modified.
范例:
QByteArray byteArray("abc");
QBuffer buffer;
buffer.setBuffer(&byteArray);
buffer.open(QIODevice.WriteOnly);
buffer.seek(3);
buffer.write("def", 3);
buffer.close();
// byteArray == "abcdef"
若 byteArray is 0, the buffer creates its own internal QByteArray to work on. This byte array is initially empty.
另请参阅 buffer (), setData (),和 open ().
Sets the contents of the internal buffer to be data . This is the same as assigning data to buffer ().
什么都不做若 isOpen () 是 true.
这是重载函数。
Sets the contents of the internal buffer to be the first size bytes of data .
重实现自 QIODevice.size ().
重实现自 QIODevice.writeData ().