当前位置: 首页>>代码示例>>C++>>正文


C++ QBuffer::bytesAvailable方法代码示例

本文整理汇总了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();
}
开发者ID:KDE,项目名称:calligra-history,代码行数:33,代码来源:psd_resource_section.cpp

示例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);
}
开发者ID:IGLOU-EU,项目名称:krita,代码行数:43,代码来源:psd_utils_test.cpp

示例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;
}
开发者ID:oktal,项目名称:Bombermelee,代码行数:23,代码来源:cnetworkmanager.cpp


注:本文中的QBuffer::bytesAvailable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。