这里有点混乱:我正在尝试这样做:
QBuffer _ourLogMessageBuffer;
QByteArray theLogMessage;
...
qDebug() << "Writing " << theLogMessage.size() << " bytes to buffer\n";
qint64 numberOfBytes - _ourLogMessagesBuffer.write(theLogMessage);
qDebug() << "Wrote " << numberOfBytes << " bytes to buffer\n";
qDebug() << "Buffer has " << _ourLogMessagesBuffer.bytesAvailable()
<< " bytes available to read (after write)\n";
这将输出以下内容:
Writing 196 bytes to buffer
Wrote 196 bytes to buffer
Buffer has 0 bytes available to read (after write)
最后一行真的让我很困惑。我认为 .write() 方法的返回值应该说明写入了多少字节?为什么它们不可用?
而且,后来,我尝试了以下操作:
qDebug() << "Buffer has " << _ourLogMessagesBuffer.bytesAvailable()
<< " bytes available to read (before read)\n";
char logMessageBytes[565];
qint64 numberOfBytes = _ourLogMessagesBuffer.read(logMessageBytes, 565);
qDebug() << "Read " << numberOfBytes << " bytes from buffer\n";
考虑到前面的 bytesAvailable 结果,这些调用的输出并不太令人惊讶。他们输出以下内容:
Buffer has 0 bytes available to read (before read)
Read 0 bytes from buffer
所以我觉得我错过了一步,你必须在写入和可供读取的数据之间做一些事情。也许某种寻求或什么?但我似乎错过了文档中的说明。
任何提示将不胜感激。谢谢!