QBuffer类提供QIODevice接口为QByteArray. 更多 …
QBufferallows you to access aQByteArray使用QIODevice接口。QByteArray仅仅被视为标准随机访问文件。范例: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'默认情况下,内部
QByteArraybuffer is created for you when you create aQBuffer. You can access this buffer directly by callingbuffer(). You can also useQBufferwith an existingQByteArray通过调用setBuffer(), or by passing your array toQBuffer‘s constructor.调用
open()to open the buffer. Then callwrite()orputChar()to write to the buffer, andread(),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 callingseek(). When you are done with accessing the buffer, callclose().下列代码片段展示如何把数据写入
QByteArray使用QDataStreamandQBuffer:QByteArray byteArray; QBuffer buffer(&byteArray); buffer.open(QIODevice::WriteOnly); QDataStream out(&buffer); out << QApplication::palette();Effectively, we convert the application’s
QPaletteinto a byte array. Here’s how to read the data from theQByteArray:QPalette palette; QBuffer buffer(&byteArray); buffer.open(QIODevice::ReadOnly); QDataStream in(&buffer); in >> palette;
QTextStreamandQDataStreamalso provide convenience constructors that take aQByteArrayand that create aQBufferbehind the scenes.
QBuffer发射readyRead()when new data has arrived in the buffer. By connecting to this signal, you can useQBufferto store temporary data before processing it.QBufferalso emitsbytesWritten()every time new data has been written to the buffer.
QBuffer
(
buf
[
,
parent=None
]
)
¶
QBuffer([parent=None])
- param parent
- param buf
构造
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.
范例:
QByteArray byteArray("abc");
QBuffer buffer(&byteArray);
buffer.open(QIODevice::WriteOnly);
buffer.seek(3);
buffer.write("def", 3);
buffer.close();
// byteArray == "abcdef"
另请参阅
open()
setBuffer()
setData()
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()
PySide2.QtCore.QBuffer.
buffer
(
)
¶
这是重载函数。
这如同
data()
.
PySide2.QtCore.QBuffer.
data
(
)
¶
返回包含在缓冲中的数据。
这如同
buffer()
.
另请参阅
setData()
setBuffer()
PySide2.QtCore.QBuffer.
setBuffer
(
a
)
¶
a
–
QByteArray
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 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
None
, the buffer creates its own internal
QByteArray
to work on. This byte array is initially empty.
另请参阅
buffer()
setData()
open()
PySide2.QtCore.QBuffer.
setData
(
data
)
¶
data
–
QByteArray
Sets the contents of the internal buffer to be
data
. This is the same as assigning
data
to
buffer()
.
什么都不做若
isOpen()
为 true。
另请参阅
data()
setBuffer()