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


C++ QByteArray::reserve方法代码示例

本文整理汇总了C++中QByteArray::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ QByteArray::reserve方法的具体用法?C++ QByteArray::reserve怎么用?C++ QByteArray::reserve使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QByteArray的用法示例。


在下文中一共展示了QByteArray::reserve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: initiateTTHSearch

bool Dispatcher::initiateTTHSearch(QByteArray tth)
{
    // Dispatch to forwarding peers
    QList<QHostAddress> forwardingPeers = networkTopology->getForwardingPeers(3);
    QListIterator<QHostAddress> it(forwardingPeers);
    while(it.hasNext())
    {
        QHostAddress h = it.next();
        sendTTHSearchForwardRequest(h, tth);
    }

    // Dispatch in own bucket if bootstrapped broadcast or multicast
    QByteArray datagram;
    datagram.reserve(26);
    if (networkBootstrap->getBootstrapStatus() == NETWORK_MCAST)
        datagram.append(MulticastPacket);
    else if (networkBootstrap->getBootstrapStatus() == NETWORK_BCAST)
        datagram.append(BroadcastPacket);
    else
        return false;
    datagram.append(TTHSearchRequestPacket);

    datagram.append(tth);
    // TODO: Uncomment in version 0.1.10, this breaks compatibility with 0.1.8 release
    //       Parsing of this tag added in 0.1.9
    //datagram.append(quint32ToByteArray(tthSearchId));
    tthSearchId++;

    if (networkBootstrap->getBootstrapStatus() == NETWORK_MCAST)
        sendMulticastRawDatagram(datagram);
    else if (networkBootstrap->getBootstrapStatus() == NETWORK_BCAST)
        sendBroadcastRawDatagram(datagram);

    return true;
}
开发者ID:BackupGGCode,项目名称:arpmanetdc,代码行数:35,代码来源:dispatcher.cpp

示例2: accept

void EditBookmarksDialog::accept() {
  // save bookmarks
  // it's easier to recreate the whole bookmark file than
  // to manipulate FmBookmarks object. So here we generate the file directly.
  QByteArray buf;
  buf.reserve(4096);
  for(int row = 0; ; ++row) {
    QTreeWidgetItem* item = ui->treeWidget->topLevelItem(row);
    if(!item)
      break;
    QString name = item->data(0, Qt::DisplayRole).toString();
    QString path = item->data(1, Qt::DisplayRole).toString();
    QUrl url = QUrl::fromUserInput(path);
    buf.append(url.toEncoded());
    buf.append(' ');
    buf.append(name.toUtf8());
    buf.append('\n');
  }

  // FIXME: should we support Qt or KDE specific bookmarks in the future?
  char* outputFile = g_build_filename(g_get_home_dir(), ".gtk-bookmarks", NULL);
  // we use glib API here because the API is atomic.
  g_file_set_contents(outputFile, buf.constData(), buf.length(), NULL);
  g_free(outputFile);
  QDialog::accept();
}
开发者ID:GinoM,项目名称:pcmanfm-qt,代码行数:26,代码来源:editbookmarksdialog.cpp

示例3:

QByteArray Util::base32encode(const QByteArray &in) {
	QByteArray rc;
	rc.reserve(cyoBase32EncodeGetLength(in.length()));
	rc.resize(cyoBase32Encode(rc.data(), in.constData(), in.length()));

	return rc;
}
开发者ID:lokjaiswal12,项目名称:workingDraft,代码行数:7,代码来源:Util.cpp

示例4: env

QProcessEnvironment PokyRunner::Private::updateEnvironment(const QProcessEnvironment &environment)
{
    QProcessEnvironment env(environment);
    QProcess proc;
    QStringList args;
    args << QLatin1String("-c")
         << QString(QLatin1String(". \"%1\"; env")).arg(envFile);

    proc.start(QLatin1String("sh"), args);
    if (!proc.waitForFinished(5000))
    {
        qWarning() << "[PokyRunner]: Failed to retrieve poky environment from" << envFile;
        proc.kill();
    }
    QByteArray buff;
    buff.reserve(4096);
    qint64 len;

    while ((len = proc.readLine(buff.data(), 4096)) > 0)
    {
        buff.resize(len - 1);
        QString line = QString::fromLatin1(buff);
        int idx = line.indexOf(QLatin1Char('='));
        if (idx < 0)
            qWarning() << "[PokyRunner]: Corrupted output" << line;
        else
            env.insert(line.left(idx), line.mid(idx + 1));
    }
    return env;
}
开发者ID:fargies,项目名称:qtcreator-plugin-pokysdk,代码行数:30,代码来源:pokyrunner.cpp

示例5: QMetaObject_normalizedSignatureQt47

QByteArray QMetaObject_normalizedSignatureQt47(const char *method)
{
    QByteArray result;
    if (!method || !*method)
        return result;
    int len = int(strlen(method));
    QVarLengthArray<char> stackbuf(len + 1);
    char *d = stackbuf.data();
    qRemoveWhitespace(method, d);

    result.reserve(len);

    int argdepth = 0;
    int templdepth = 0;
    while (*d) {
        if (argdepth == 1)
            d = qNormalizeTypeQt47(d, templdepth, result);
        if (*d == '(')
            ++argdepth;
        if (*d == ')')
            --argdepth;
        result += *d++;
    }

    return result;
}
开发者ID:BadSingleton,项目名称:shiboken2,代码行数:26,代码来源:shibokennormalize.cpp

示例6: readImage

QString AMCImporter::readImage(const QString& format_) {
  if(m_failed) {
    return QString();
  }
  quint32 l = readInt();
  if(l == 0) {
    return QString();
  }
  if(l > AMC_MAX_STRING_SIZE) {
    myDebug() << "string is too long:" << l;
    m_failed = true;
    return QString();
  }
  QVector<char> buffer(l+1);
  m_ds.readRawData(buffer.data(), l);
  QByteArray bytes;
  bytes.reserve(l);
  qCopy(buffer.data(), buffer.data() + l, bytes.begin());
  QImage img = QImage::fromData(bytes);
  if(img.isNull()) {
    myDebug() << "null image";
    return QString();
  }
  QString format = QLatin1String("PNG");
  if(format_ == QLatin1String(".jpg")) {
    format = QLatin1String("JPEG");
  } else if(format_ == QLatin1String(".gif")) {
    format = QLatin1String("GIF");
  }
  return ImageFactory::addImage(img, format);
}
开发者ID:KDE,项目名称:tellico,代码行数:31,代码来源:amcimporter.cpp

示例7: serializeList

QByteArray KConfigGroupPrivate::serializeList(const QList<QByteArray> &list)
{
    QByteArray value = "";

    if (!list.isEmpty()) {
        QList<QByteArray>::ConstIterator it = list.constBegin();
        const QList<QByteArray>::ConstIterator end = list.constEnd();

        value = QByteArray(*it).replace('\\', "\\\\").replace(',', "\\,");

        while (++it != end) {
            // In the loop, so it is not done when there is only one element.
            // Doing it repeatedly is a pretty cheap operation.
            value.reserve(4096);

            value += ',';
            value += QByteArray(*it).replace('\\', "\\\\").replace(',', "\\,");
        }

        // To be able to distinguish an empty list from a list with one empty element.
        if (value.isEmpty())
            value = "\\0";
    }

    return value;
}
开发者ID:crayonink,项目名称:calligra-2,代码行数:26,代码来源:kconfiggroup.cpp

示例8: readData

qint64 CryptFileDevice::readData(char *data, qint64 len)
{
    if (!m_encrypted)
    {
        qint64 fileRead = m_device->read(data, len);
        return fileRead;
    }

    if (len == 0)
        return m_device->read(data, len);

    QByteArray ba;
    ba.reserve(len);
    do {
        qint64 maxSize = len - ba.length();

        qint64 size = readBlock(maxSize, ba);

        if (size == 0)
            break;
    } while (ba.length() < len);

    if (ba.isEmpty())
        return 0;

    memcpy(data, ba.data(), ba.length());

    return ba.length();
}
开发者ID:Vardan07,项目名称:CryptFileDevice,代码行数:29,代码来源:cryptfiledevice.cpp

示例9: _gotPacket

void Discovery::_gotPacket() {
	QHostAddress address;
	QByteArray buff;
	quint16 port;

	while (mSock.hasPendingDatagrams()) {
		qint64 size = mSock.pendingDatagramSize();
		buff.reserve(size);

		buff.resize(mSock.readDatagram(buff.data(), size, &address, &port));

		if (buff.startsWith("BSYNC\0")) {
			/// @todo Use some other means to distinguish between tracker TrackerResponse and Announce
			if (port == 3000) {
				TrackerResponse resp = TrackerResponse::fromBinary(buff);
				emit gotTrackerResponse(resp);
			}
			else {
				Announce req = Announce::fromBinary(buff);
				emit gotPeerResponse(req, address, port);
			}
		}
		else {

		}
		emit gotPacket(buff, address, port);
	}
}
开发者ID:lokjaiswal12,项目名称:workingDraft,代码行数:28,代码来源:Discovery.cpp

示例10: effectStyle

QByteArray PHISHtmlGeneric::effectStyle() const
{
    QByteArray arr;
    arr.reserve( 400 );
    if ( _it->hasGraphicEffect() ) {
        if ( _it->effect()->graphicsType()==PHIEffect::GTShadow ) {
            arr+=textShadowStyle();
            if ( arr.isEmpty() ) {
                QColor c;
                qreal xOff, yOff, radius;
                _it->effect()->shadow( c, xOff, yOff, radius );
                arr+=boxShadowKeyword()+':'+QByteArray::number( static_cast<int>(xOff) )+"px ";
                arr+=QByteArray::number( static_cast<int>(yOff) )+"px ";
                arr+=QByteArray::number( static_cast<int>(radius) )+"px ";
                arr+=c.name().toLatin1()+';';
            }
        }
    }
    QTransform t=transformation();
    if ( t.isIdentity() ) return arr;
    arr+=transformOriginKeyword()+":0 0;";
    arr+=transformKeyword()+":matrix("+QByteArray::number( t.m11(), 'f' )
        +','+QByteArray::number( t.m12(), 'f' )+','+QByteArray::number( t.m21(), 'f' )
        +','+QByteArray::number( t.m22(), 'f' )+','+QByteArray::number( static_cast<int>(t.m31()) )
        +','+QByteArray::number( static_cast<int>(t.m32()) )+");";
    return arr;
}
开发者ID:TheAppsDude,项目名称:phisketeer,代码行数:27,代码来源:phishtmlgeneric.cpp

示例11: foreach

    // complementary
    foreach(U2Region complementaryRegion, regionsComplementary){
        translatedSeq.clear();

        U2SequenceImporter importer;
        importer.startSequence(stateInfo, dbiRef, U2ObjectDbi::ROOT_FOLDER, seqObj->getSequenceName()+ " " + resultName + QString(" %1").arg(currentSeq) + " complementary", false);

        QByteArray complementarySeq;
        char* complSeq = NULL;

        int blockCounter = 0;
        qint64 end = complementaryRegion.endPos() - 1  - complementaryRegion.length / 3 * 3;

        for(qint64 i = complementaryRegion.endPos() - 1 ; i > end ;i-=3, blockCounter += 3){
            if( (blockCounter % NUM_DB_READ) == 0 ){
                importer.addBlock(translatedSeq.constData(), translatedSeq.size(), stateInfo);
                complementarySeq.clear();
                seq.clear();
                translatedSeq.clear();
                seq = seqObj->getSequenceData(U2Region(qMax(end + 1, static_cast<qint64>(i - NUM_DB_READ + 1)), qMin(static_cast<qint64>(NUM_DB_READ), i - end)), stateInfo);
                CHECK_OP(stateInfo, );
                complementarySeq.reserve(seq.size());
                complSeq = complementarySeq.data();
                TextUtils::translate(complTT->getOne2OneMapper(), seq, seq.size(), complSeq);
                TextUtils::reverse(complSeq, seq.size());
                blockCounter = 0;

            }
            SAFE_POINT(complSeq != NULL, "complSeq is NULL", );
            translatedSeq.append(aminoTT->translate3to1(complSeq[blockCounter], complSeq[blockCounter + 1], complSeq[blockCounter + 2]));
        }
开发者ID:ggrekhov,项目名称:ugene,代码行数:31,代码来源:AminoTranslationWorker.cpp

示例12: dehuffman

QByteArray dehuffman(QByteArray data, MainWindow *mainWindow)
{
	QHash<quint8, QBitArray> codes;
	qint32 size;
	QBitArray bits;
	{
		QDataStream stream(data);
		stream >> codes >> size >> bits;
		Q_ASSERT(stream.status() == QDataStream::Ok);
	}

	QHash<QBitArray, quint8> table;
	for (int i = 0; i < tableSize; ++i)
		if (codes.contains(i))	table[codes[i]] = i;

	QByteArray result;
	result.reserve(data.size());

	int index = 0;
	for (int i = 0; i < size; ++i)
	{
		mainWindow->setProgress(qRound(static_cast<qreal>(100 * i) / size));

		QBitArray b;
		while (!table.contains(b))
		{
			b.resize(b.size() + 1);
			if (bits[index])	b.setBit(b.size() - 1);
			++index;
		}
		result.append(table[b]);
	}

	return result;
}
开发者ID:Etrnls,项目名称:etrnlabs,代码行数:35,代码来源:huffman.cpp

示例13: handleReceivedCIDPingForwardRequest

// forward the CID ping to own bucket on request
void Dispatcher::handleReceivedCIDPingForwardRequest(QHostAddress &fromAddr, QByteArray &data)
{
    data.remove(0, 2);
    QByteArray tmp = data.mid(0, 4);
    QHostAddress allegedFromHost = QHostAddress(getQuint32FromByteArray(&tmp));
    if (fromAddr != allegedFromHost)
        return;

    QByteArray datagram;
    datagram.reserve(30);
    switch(networkBootstrap->getBootstrapStatus())
    {
    case NETWORK_MCAST:
        datagram.append(MulticastPacket);
        datagram.append(CIDPingForwardedPacket);
        datagram.append(data);
        sendMulticastRawDatagram(datagram);
        break;
    case NETWORK_BCAST:
        datagram.append(BroadcastPacket);
        datagram.append(CIDPingForwardedPacket);
        datagram.append(data);
        sendBroadcastRawDatagram(datagram);
        break;
    }
}
开发者ID:BackupGGCode,项目名称:arpmanetdc,代码行数:27,代码来源:dispatcher.cpp

示例14: handleReceivedTTHSearchForwardRequest

void Dispatcher::handleReceivedTTHSearchForwardRequest(QHostAddress &fromAddr, QByteArray &datagram)
{
    QByteArray tmp = datagram.mid(2, 4);
    QHostAddress allegedFromHost = QHostAddress(getQuint32FromByteArray(&tmp));
    if (fromAddr != allegedFromHost)
        return;

    QByteArray searchToForward;
    searchToForward.reserve(30);
    if (networkBootstrap->getBootstrapStatus() == NETWORK_MCAST)
        searchToForward.append(MulticastPacket);
    else if (networkBootstrap->getBootstrapStatus() == NETWORK_BCAST)
        searchToForward.append(BroadcastPacket);

    searchToForward.append(TTHSearchRequestPacket);
    searchToForward.append(datagram.mid(2));
    if (networkBootstrap->getBootstrapStatus() == NETWORK_MCAST)
        sendMulticastRawDatagram(searchToForward);
    else if (networkBootstrap->getBootstrapStatus() == NETWORK_BCAST)
        sendBroadcastRawDatagram(searchToForward);
    // else drop silently

    handleReceivedTTHSearchQuestion(fromAddr, datagram);

    emit searchForwardReceived(); // stats
    //qDebug() << "Dispatcher::handleReceivedTTHSearchForwardRequest() from alleged datagram" << fromAddr << allegedFromHost << datagram.toBase64();
}
开发者ID:BackupGGCode,项目名称:arpmanetdc,代码行数:27,代码来源:dispatcher.cpp

示例15: saveState

bool Emu::saveState(const QString &statePath)
{
	emsl.save = true;

	QByteArray data;
	data.reserve(10*1024*1024);

	QDataStream s(&data, QIODevice::WriteOnly);
	s.setByteOrder(QDataStream::LittleEndian);
	s.setFloatingPointPrecision(QDataStream::SinglePrecision);
	if (!saveInternal(&s))
		return false;

	QFile file(statePath);
	if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
		emsl.error = tr("Could not open file for writing.");
		return false;
	}

	s.setDevice(&file);
	s << frame().copy(videoSrcRect().toRect());
	QByteArray compressed = qCompress(data);
	bool ok = (file.write(compressed) == compressed.size());
	file.close();
	if (!ok)
		file.remove();
	return ok;
}
开发者ID:V10lator,项目名称:emumaster,代码行数:28,代码来源:emu.cpp


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