本文整理汇总了C++中QBuffer::bytesAvailable方法的典型用法代码示例。如果您正苦于以下问题:C++ QBuffer::bytesAvailable方法的具体用法?C++ QBuffer::bytesAvailable怎么用?C++ QBuffer::bytesAvailable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QBuffer
的用法示例。
在下文中一共展示了QBuffer::bytesAvailable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: read
bool PSDResourceSection::read(QIODevice* io)
{
quint32 resourceBlockLength = 0;
if (!psdread(io, &resourceBlockLength)) {
error = "Could not read resource block length";
return false;
}
dbgFile << "Resource block length" << resourceBlockLength << "starts at" << io->pos();
QByteArray ba = io->read(resourceBlockLength);
if ((quint32)ba.size() != resourceBlockLength) {
error = "Could not read all resources";
return false;
}
QBuffer buf;
buf.setBuffer(&ba);
buf.open(QBuffer::ReadOnly);
while (!buf.atEnd()) {
PSDResourceBlock* block = new PSDResourceBlock();
if (!block->read(&buf)) {
error = "Error reading block: " + block->error;
return false;
}
dbgFile << "resource block created. Type:" << block->identifier << "size"
<< block->dataSize
<< "," << buf.bytesAvailable() << "bytes to go";
resources[(PSDResourceID)block->identifier] = block;
}
return valid();
}
示例2: test_psdread_pascalstring
void PSDUtilsTest::test_psdread_pascalstring()
{
QBuffer buf;
QString s;
QString r;
// test null string
buf.open(QBuffer::ReadWrite);
QVERIFY(psdwrite_pascalstring(&buf, s));
buf.close();
buf.open(QBuffer::ReadOnly);
psdread_pascalstring(&buf, r, 2);
QCOMPARE(r, s);
QVERIFY(buf.bytesAvailable() == 0);
// test even string
buf.close();
buf.buffer().clear();
r.clear();
buf.open(QBuffer::ReadWrite);
s = QString("bl");
QVERIFY(psdwrite_pascalstring(&buf, s));
buf.close();
buf.open(QBuffer::ReadOnly);
psdread_pascalstring(&buf, r, 1);
QCOMPARE(r, s);
QVERIFY(buf.bytesAvailable() == 0);
// test uneven string
buf.close();
buf.buffer().clear();
r.clear();
buf.open(QBuffer::ReadWrite);
s = QString("bla");
QVERIFY(psdwrite_pascalstring(&buf, s, 2));
buf.close();
buf.open(QBuffer::ReadOnly);
psdread_pascalstring(&buf, r, 2);
QCOMPARE(r, s);
dbgKrita << buf.bytesAvailable();
QVERIFY(buf.bytesAvailable() == 0);
}
示例3: stream
QList<QByteArray> CNetworkManager::getPacketsFromBuffer(QByteArray &buffer)
{
QList<QByteArray> ret;
QByteArray packet;
QByteArray endOfFrame;
QDataStream stream(&endOfFrame, QIODevice::WriteOnly);
stream << (quint32) 0xFFFF << (quint32) 0xFFFF;
QBuffer in;
in.setBuffer(&buffer);
in.open(QIODevice::ReadOnly);
do
{
QByteArray c = in.read(1);
packet.append(c);
if (packet.contains(endOfFrame))
{
ret.append(packet);
packet.clear();
}
} while (in.bytesAvailable());
return ret;
}