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


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

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


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

示例1: write

void QDBusMetaObjectGenerator::write(QDBusMetaObject *obj)
{
    // this code here is mostly copied from qaxbase.cpp
    // with a few modifications to make it cleaner
    
    QString className = interface;
    className.replace(QLatin1Char('.'), QLatin1String("::"));
    if (className.isEmpty())
        className = QLatin1String("QDBusInterface");

    QVarLengthArray<int> idata;
    idata.resize(sizeof(QDBusMetaObjectPrivate) / sizeof(int));

    QDBusMetaObjectPrivate *header = reinterpret_cast<QDBusMetaObjectPrivate *>(idata.data());
    header->revision = 1;
    header->className = 0;
    header->classInfoCount = 0;
    header->classInfoData = 0;
    header->methodCount = methods.count();
    header->methodData = idata.size();
    header->propertyCount = properties.count();
    header->propertyData = header->methodData + header->methodCount * 5;
    header->enumeratorCount = 0;
    header->enumeratorData = 0;
    header->propertyDBusData = header->propertyData + header->propertyCount * 3;
    header->methodDBusData = header->propertyDBusData + header->propertyCount * intsPerProperty;

    int data_size = idata.size() +
                    (header->methodCount * (5+intsPerMethod)) +
                    (header->propertyCount * (3+intsPerProperty));
    foreach (const Method &mm, methods)
        data_size += 2 + mm.inputTypes.count() + mm.outputTypes.count();
    idata.resize(data_size + 1);

    char null('\0');
    QByteArray stringdata = className.toLatin1();
    stringdata += null;
    stringdata.reserve(8192);

    int offset = header->methodData;
    int signatureOffset = header->methodDBusData;
    int typeidOffset = header->methodDBusData + header->methodCount * intsPerMethod;
    idata[typeidOffset++] = 0;                           // eod

    // add each method:
    for (QMap<QByteArray, Method>::ConstIterator it = methods.constBegin();
         it != methods.constEnd(); ++it) {
        // form "prototype\0parameters\0typeName\0tag\0methodname\0inputSignature\0outputSignature"
        const Method &mm = it.value();

        idata[offset++] = stringdata.length();
        stringdata += it.key();                 // prototype
        stringdata += null;
        idata[offset++] = stringdata.length();
        stringdata += mm.parameters;
        stringdata += null;
        idata[offset++] = stringdata.length();
        stringdata += mm.typeName;
        stringdata += null;
        idata[offset++] = stringdata.length();
        stringdata += mm.tag;
        stringdata += null;
        idata[offset++] = mm.flags;

        idata[signatureOffset++] = stringdata.length();
        stringdata += mm.name;
        stringdata += null;
        idata[signatureOffset++] = stringdata.length();
        stringdata += mm.inputSignature;
        stringdata += null;
        idata[signatureOffset++] = stringdata.length();
        stringdata += mm.outputSignature;
        stringdata += null;

        idata[signatureOffset++] = typeidOffset;
        idata[typeidOffset++] = mm.inputTypes.count();
        memcpy(idata.data() + typeidOffset, mm.inputTypes.data(), mm.inputTypes.count() * sizeof(int));
        typeidOffset += mm.inputTypes.count();

        idata[signatureOffset++] = typeidOffset;
        idata[typeidOffset++] = mm.outputTypes.count();
        memcpy(idata.data() + typeidOffset, mm.outputTypes.data(), mm.outputTypes.count() * sizeof(int));
        typeidOffset += mm.outputTypes.count();
    }

    Q_ASSERT(offset == header->propertyData);
    Q_ASSERT(signatureOffset == header->methodDBusData + header->methodCount * intsPerMethod);
    Q_ASSERT(typeidOffset == idata.size());

    // add each property
    signatureOffset = header->propertyDBusData;
    for (QMap<QByteArray, Property>::ConstIterator it = properties.constBegin();
         it != properties.constEnd(); ++it) {
        const Property &mp = it.value();

        // form is "name\0typeName\0signature\0"
        idata[offset++] = stringdata.length();
        stringdata += it.key();                 // name
        stringdata += null;
        idata[offset++] = stringdata.length();
//.........这里部分代码省略.........
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:101,代码来源:qdbusmetaobject.cpp

示例2: open

bool SIDPlay::open(const QString &_url, bool tracksOnly)
{
	QString prefix, url, param;
	const bool hasPluginPrefix = Functions::splitPrefixAndUrlIfHasPluginPrefix(_url, &prefix, &url, &param);

	if (tracksOnly == hasPluginPrefix)
		return false;

	int track = 0;
	if (!hasPluginPrefix)
	{
		if (url.startsWith(SIDPlayName "://"))
			return false;
		url = _url;
	}
	else
	{
		if (prefix != SIDPlayName)
			return false;
		bool ok;
		track = param.toInt(&ok);
		if (track < 0 || !ok)
			return false;
	}

	if (Reader::create(url, m_reader))
	{
		const QByteArray data = m_reader->read(m_reader->size());
		m_reader.clear();

		m_tune = new SidTune((const quint8 *)data.data(), data.length());
		if (!m_tune->getStatus())
			return false;

		if (!hasPluginPrefix)
		{
			m_aborted = true;
			m_url = url;
			return true;
		}

		const SidTuneInfo *info = m_tune->getInfo();

		if (track >= (int)info->songs())
			return false;

		m_rs.create(m_sidplay.info().maxsids());
		if (!m_rs.getStatus())
			return false;
		m_rs.filter(true);

#if ((LIBSIDPLAYFP_VERSION_MAJ << 16 | LIBSIDPLAYFP_VERSION_MIN << 8 | LIBSIDPLAYFP_VERSION_LEV) > 0x010800)
		const bool isStereo = info->sidChips() > 1 ? true : false;
#else
		const bool isStereo = info->isStereo();
#endif

		SidConfig cfg;
		cfg.frequency = m_srate;
		cfg.sidEmulation = &m_rs;
		if (isStereo)
			cfg.playback = SidConfig::STEREO;
		cfg.samplingMethod = SidConfig::INTERPOLATE;
		if (!m_sidplay.config(cfg))
			return false;

		m_tune->selectSong(track + 1);

		m_title = getTitle(info, track);
		m_chn = isStereo ? 2 : 1;

		const QString title    = info->infoString(0);
		const QString author   = info->infoString(1);
		const QString released = info->infoString(2);
		if (!title.isEmpty())
			m_tags << qMakePair(QString::number(QMPLAY2_TAG_TITLE), title);
		if (!author.isEmpty())
			m_tags << qMakePair(QString::number(QMPLAY2_TAG_ARTIST), author);
		if (!released.isEmpty())
			m_tags << qMakePair(QString::number(QMPLAY2_TAG_DATE), released);
		m_tags << qMakePair(tr("Track"), QString::number(track + 1));

		streams_info += new StreamInfo(m_srate, m_chn);

		return m_sidplay.load(m_tune);
	}

	return false;
}
开发者ID:biddyweb,项目名称:QMPlay2,代码行数:89,代码来源:SIDPlay.cpp

示例3: GetBody

QByteArray QProcessResponseThread::GetBody( QByteArray &byStream )
{
    return byStream.right( byStream.length( ) - Protocol::nHeadLength );
}
开发者ID:Anne081031,项目名称:ParkCode,代码行数:4,代码来源:qprocessresponsethread.cpp

示例4: startParseSetColorTask

void ApiServerSetColorTask::startParseSetColorTask(QByteArray buffer)
{
    API_DEBUG_OUT << QString(buffer) << "task thread:" << thread()->currentThreadId();
    bool isReadFail = false;

    // buffer can contains only something like this:
    // 1-34,9,125
    // 2-0,255,0;3-0,255,0;6-0,255,0;

    while (buffer.isEmpty() == false)
    {
        if (isReadFail == true)
        {
            qWarning() << "got it!";
        }

        // Check buffer length, minimum 7 - '2-0,0,0'
        if (buffer.length() < 7)
        {
            API_DEBUG_OUT << "error: buffer.length() < 7";
            isReadFail = true;
            goto end;
        }

        // Read led number
        int ledNumber = LightpackMath::getDigit(buffer[0]); // first char of ledNumber
        int ledNumber2 = LightpackMath::getDigit(buffer[1]); // second char of ledNumber
        if (ledNumber > 0)
        {
            if (buffer[1] == '-')
            {
                buffer.remove(0, 2); // remove "2-"
            }
            else if (ledNumber2 >= 0 && buffer[2] == '-')
            {
                ledNumber = ledNumber * 10 + ledNumber2; // 10,11,12..99
                buffer.remove(0, 3); // remove "10-"
            } else {
                API_DEBUG_OUT << "lednumber fail:" << QString(buffer);
                isReadFail = true;
                goto end;
            }
        } else {
            API_DEBUG_OUT << "isdigit fail:" << QString(buffer);
            isReadFail = true;
            goto end;
        }

        API_DEBUG_OUT << "lednumber-" << ledNumber << "buff-" << QString(buffer);

        if (ledNumber <= 0 || ledNumber > m_numberOfLeds)
        {
            API_DEBUG_OUT << "ledNumber is out of bounds:" << ledNumber;
            isReadFail = true;
            goto end;
        }

        // Convert for using in zero-based arrays
        ledNumber = ledNumber - 1;

        // Read led red, green and blue colors to buffer buffRgb[]
        int indexBuffer = 0;
        int indexRgb = 0;        
        memset(buffRgb, 0, sizeof(buffRgb));

        bool isDigitExpected = true;
        for (indexBuffer = 0; indexBuffer < buffer.length(); indexBuffer++)
        {
            int d = LightpackMath::getDigit(buffer[indexBuffer]);
            if (d < 0)
            {
                if (buffer[indexBuffer] == ';')
                {
                    break;
                }
                else if (buffer[indexBuffer] != ',')
                {
                    API_DEBUG_OUT << "expected comma, buffer:" << QString(buffer) << indexBuffer << buffer[indexBuffer];
                    isReadFail = true;
                    goto end;
                }
                else if (isDigitExpected)
                {
                    API_DEBUG_OUT << "expected digit, buffer:" << QString(buffer) << indexBuffer << buffer[indexBuffer];
                    isReadFail = true;
                    goto end;
                }
                isDigitExpected = true;
                indexRgb++;
            } else {
                buffRgb[indexRgb] *= 10;
                buffRgb[indexRgb] += d;

                isDigitExpected = false;

                if (buffRgb[indexRgb] > 255)
                {
                    API_DEBUG_OUT << "rgb value > 255";
                    isReadFail = true;
                    goto end;
//.........这里部分代码省略.........
开发者ID:Gimazov,项目名称:Lightpack,代码行数:101,代码来源:ApiServerSetColorTask.cpp

示例5: read

void MidiInstrument::read(Xml& xml)
      {
      bool ok;
      int base = 10;
      _nullvalue = -1;
      for (;;) {
            Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            switch (token) {
                  case Xml::Error:
                  case Xml::End:
                        return;
                  case Xml::TagStart:
                        if (tag == "Patch") {
                              Patch* patch = new Patch;
                              patch->read(xml);
                              if (pg.empty()) {
                                    PatchGroup* p = new PatchGroup;
                                    p->patches.push_back(patch);
                                    pg.push_back(p);
                                    }
                              else
                                    pg[0]->patches.push_back(patch);
                              }
                        else if (tag == "PatchGroup") {
                              PatchGroup* p = new PatchGroup;
                              p->read(xml);
                              pg.push_back(p);
                              }
                        else if (tag == "Controller") {
                              MidiController* mc = new MidiController();
                              mc->read(xml);
                              // Added by Tim. Copied from muse 2.
                              //
                              // HACK: make predefined "Program" controller overloadable
                              //
                              if (mc->name() == "Program") {
                                    for (iMidiController i = _controller->begin(); i != _controller->end(); ++i) {
                                          if (i->second->name() == mc->name()) {
                                                delete i->second;
                                                _controller->erase(i);
                                                break;
                                                }
                                          }
                                    }
                                    
                              _controller->add(mc);
                              }
                        else if (tag == "Drummaps") {
                              readDrummaps(xml);
                              }
                        else if (tag == "Init")
                              readEventList(xml, _midiInit, "Init");
                        else if (tag == "Reset")
                              readEventList(xml, _midiReset, "Reset");
                        else if (tag == "State")
                              readEventList(xml, _midiState, "State");
                        else if (tag == "InitScript") {
                              if (_initScript)
                                    delete _initScript;
                              QByteArray ba = xml.parse1().toLatin1();
                              const char* istr = ba.constData();
                              int len = ba.length() +1;
                              if (len > 1) {
                                    _initScript = new char[len];
                                    memcpy(_initScript, istr, len);
                                    }
                              }
                        else if (tag == "SysEx") {
                              SysEx* se = new SysEx;
                              if(!se->read(xml))
                              {
                                delete se;
                                printf("MidiInstrument::read():SysEx: reading sysex failed\n");
                              }
                              else
                                _sysex.append(se);
                              }
                        else
                              xml.unknown("MidiInstrument");
                        break;
                  case Xml::Attribut:
                        if (tag == "name")
                              setIName(xml.s2());
                        else if(tag == "nullparam") {
                              _nullvalue = xml.s2().toInt(&ok, base);
                        }
                        break;
                  case Xml::TagEnd:
                        if (tag == "MidiInstrument")
                              return;
                  default:
                        break;
                  }
            }
      }
开发者ID:UIKit0,项目名称:lmuse,代码行数:96,代码来源:minstrument.cpp

示例6: main

int main(int argc, char **argv)
{
    QCoreApplication app(argc, argv);
    QTextCodec *big5 = QTextCodec::codecForName("Big5-hkscs");

#if 0
    QFile f("/home/lars/dev/qt-4.0/util/unicode/data/big5-eten.txt");
    f.open(QFile::ReadOnly);

    while (!f.atEnd()) {
        QByteArray line = f.readLine();
        if (line.startsWith("#"))
            continue;
        line.replace("0x", "");
        line.replace("U+", "");
        line.replace("\t", " ");
        line = line.simplified();
        QList<QByteArray> split = line.split(' ');
        bool ok;
        int b5 = split.at(0).toInt(&ok, 16);
        Q_ASSERT(ok);
        int uc = split.at(1).toInt(&ok, 16);
        Q_ASSERT(ok);
        if (b5 < 0x100)
            continue;
#else
    QFile f(":/BIG5");
    f.open(QFile::ReadOnly);

    while (!f.atEnd()) {
        QByteArray line = f.readLine();
        if (line.startsWith("CHARMAP"))
            break;
    }
    QSet<uint> b5_ok;
    QSet<uint> uc_ok;
    QList<Map> b5_to_uc_map;
    QList<Map> uc_to_b5_map;
    while (!f.atEnd()) {
        QByteArray line = f.readLine();
        if (line.startsWith("%"))
            continue;
        if (line.startsWith("END CHARMAP"))
            break;
        line.replace("/x", "");
        line.replace("<U", "");
        line.replace(">", "");
        line.replace("\t", " ");
        line = line.simplified();
        QList<QByteArray> split = line.split(' ');
        bool ok;
        int b5 = split.at(1).toInt(&ok, 16);
        Q_ASSERT(ok);
        int uc = split.at(0).toInt(&ok, 16);
        Q_ASSERT(ok);
        if (b5 < 0x100 || uc > 0xffff)
            continue;
#endif

//         qDebug() << hex << "testing: '" << b5 << "' - '" << uc << "'";
        QByteArray ba;

        ba += (char)(uchar)(b5 >> 8);
        ba += (char)(uchar)(b5 & 0xff);

        QString s = big5->toUnicode(ba);
        Q_ASSERT(s.length() == 1);
        QString s2;
        s2 = QChar(uc);
        ba = big5->fromUnicode(s2);
        Q_ASSERT(ba.length() <= 2);
        int round;
        if (ba.length() == 1)
            round = (int)(uchar)ba[0];
        else
            round = ((int)(uchar)ba[0] << 8) + (int)(uchar)ba[1];
        if (b5 != round)
            uc_to_b5_map += Map(uc, b5);
        else
            b5_ok.insert(b5);

        if (s[0].unicode() != uc)
            b5_to_uc_map += Map(uc, b5);
        else
            uc_ok.insert(uc);
    };

    QList<QByteArray> list;
    foreach(Map m, b5_to_uc_map) {
        if (!uc_ok.contains(m.b5))
            list += QByteArray("    { 0x" + QByteArray::number(m.b5, 16) + ", 0x" + QByteArray::number(m.uc, 16) + " }\n");;
    }
    QByteArray ba;
    qSort(list);
    foreach(QByteArray a, list)
        ba += a;
    qDebug() << "struct B5Map b5_to_uc_map = {\n" << ba + "\n};";

    list = QList<QByteArray>();
    foreach(Map m, uc_to_b5_map)
//.........这里部分代码省略.........
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:101,代码来源:main.cpp

示例7: fromString

    bool fromString(const QByteArray &str)
    {
        PropList list;
        int at = 0;
        while(1) {
            while (at < str.length() && (str[at] == ',' || str[at] == ' ' || str[at] == '\t'))
                ++at;
            int n = str.indexOf('=', at);
            if(n == -1)
                break;
            QByteArray var, val;
            var = str.mid(at, n-at);
            at = n + 1;
            if(str[at] == '\"') {
                ++at;
                n = str.indexOf('\"', at);
                if(n == -1)
                    break;
                val = str.mid(at, n-at);
                at = n + 1;
            }
            else {
                n = at;
                while (n < str.length() && str[n] != ',' && str[n] != ' ' && str[n] != '\t')
                    ++n;
                val = str.mid(at, n-at);
                at = n;
            }
            Prop prop;
            prop.var = var;
            if (var == "qop" || var == "cipher") {
                int a = 0;
                while (a < val.length()) {
                    while (a < val.length() && (val[a] == ',' || val[a] == ' ' || val[a] == '\t'))
                        ++a;
                    if (a == val.length())
                        break;
                    n = a+1;
                    while (n < val.length() && val[n] != ',' && val[n] != ' ' && val[n] != '\t')
                        ++n;
                    prop.val = val.mid(a, n-a);
                    list.append(prop);
                    a = n+1;
                }
            }
            else {
                prop.val = val;
                list.append(prop);
            }

            if(at >= str.size() - 1 || (str[at] != ',' && str[at] != ' ' && str[at] != '\t'))
                break;
        }

        // integrity check
        if(list.varCount("nonce") != 1)
            return false;
        if(list.varCount("algorithm") != 1)
            return false;
        *this = list;
        return true;
    }
开发者ID:BackupTheBerlios,项目名称:synapse-xmpp-svn,代码行数:62,代码来源:simplesasl.cpp

示例8: write

qint64 QProcessBackend::write(const QByteArray& byteArray)
{
    return write(byteArray.data(), byteArray.length());
}
开发者ID:qtproject,项目名称:playground-qtprocessmanager,代码行数:4,代码来源:qprocessbackend.cpp

示例9: gradientBrush

int QPdfEnginePrivate::gradientBrush(const QBrush &b, const QMatrix &matrix, int *gStateObject)
{
    const QGradient *gradient = b.gradient();
    if (!gradient)
        return 0;

    QTransform inv = matrix.inverted();
    QPointF page_rect[4] = { inv.map(QPointF(0, 0)),
                             inv.map(QPointF(width_, 0)),
                             inv.map(QPointF(0, height_)),
                             inv.map(QPointF(width_, height_)) };

    bool opaque = b.isOpaque();

    QByteArray shader;
    QByteArray alphaShader;
    if (gradient->type() == QGradient::LinearGradient) {
        const QLinearGradient *lg = static_cast<const QLinearGradient *>(gradient);
        shader = QPdf::generateLinearGradientShader(lg, page_rect);
        if (!opaque)
            alphaShader = QPdf::generateLinearGradientShader(lg, page_rect, true);
    } else {
        // #############
        return 0;
    }
    int shaderObject = addXrefEntry(-1);
    write(shader);

    QByteArray str;
    QPdf::ByteStream s(&str);
    s << "<<\n"
        "/Type /Pattern\n"
        "/PatternType 2\n"
        "/Shading " << shaderObject << "0 R\n"
        "/Matrix ["
      << matrix.m11()
      << matrix.m12()
      << matrix.m21()
      << matrix.m22()
      << matrix.dx()
      << matrix.dy() << "]\n";
    s << ">>\n"
        "endobj\n";

    int patternObj = addXrefEntry(-1);
    write(str);
    currentPage->patterns.append(patternObj);

    if (!opaque) {
        bool ca = true;
        QGradientStops stops = gradient->stops();
        int a = stops.at(0).second.alpha();
        for (int i = 1; i < stops.size(); ++i) {
            if (stops.at(i).second.alpha() != a) {
                ca = false;
                break;
            }
        }
        if (ca) {
            *gStateObject = addConstantAlphaObject(stops.at(0).second.alpha());
        } else {
            int alphaShaderObject = addXrefEntry(-1);
            write(alphaShader);

            QByteArray content;
            QPdf::ByteStream c(&content);
            c << "/Shader" << alphaShaderObject << "sh\n";

            QByteArray form;
            QPdf::ByteStream f(&form);
            f << "<<\n"
                "/Type /XObject\n"
                "/Subtype /Form\n"
                "/BBox [0 0 " << width_ << height_ << "]\n"
                "/Group <</S /Transparency >>\n"
                "/Resources <<\n"
                "/Shading << /Shader" << alphaShaderObject << alphaShaderObject << "0 R >>\n"
                ">>\n";

            f << "/Length " << content.length() << "\n"
                ">>\n"
                "stream\n"
              << content
              << "endstream\n"
                "endobj\n";

            int softMaskFormObject = addXrefEntry(-1);
            write(form);
            *gStateObject = addXrefEntry(-1);
            xprintf("<< /SMask << /S /Alpha /G %d 0 R >> >>\n"
                    "endobj\n", softMaskFormObject);
            currentPage->graphicStates.append(*gStateObject);
        }
    }

    return patternObj;
}
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:97,代码来源:qprintengine_pdf.cpp

示例10: toUnicode

/*!
    Converts \a a from the encoding of this codec to Unicode, and
    returns the result in a QString.
*/
QString QTextCodec::toUnicode(const QByteArray& a) const
{
    return convertToUnicode(a.constData(), a.length(), 0);
}
开发者ID:wpbest,项目名称:copperspice,代码行数:8,代码来源:qtextcodec.cpp

示例11: connected


//.........这里部分代码省略.........
        connect(msg, &MessageDataDeal::recvMessageData,
                this, [=] (MessageData data) {
            if (data.datatype() != FileSendType &&
                data.datatype() != commonStr)
                return;
            if (data.datatype() == commonStr)
            {
                MessageCharData *charconent = dynamic_cast<MessageCharData*>(data.content());
                if (charconent && charconent->type() == FileInfo)
                {
                    QString strinfo = QString::fromLocal8Bit(charconent->content());
                    emit recvInformation(strinfo);
                }
                return;
            }
            // write file
            FileDataContent *content = dynamic_cast<FileDataContent*>(data.content());
            if (!content)
                return;
            FileDataContent::FileHead *head = content->sendInfo();
            FileDataContent::FileNameHead *namehead = content->fileName();
            emit recvProgress(head->totalProgress >= 100 ? 99 : head->totalProgress, head->currentProgress / 100.0);
            QString filename = namehead->name.replace(namehead->path, savePath + "/");
            QFileInfo info(filename);
            emit recvInformation(cn("正在接收 %1").arg(info.fileName()));
            QDir dir(info.absolutePath());
            if (!dir.exists())
                dir.mkpath(info.absolutePath());
            if (file->fileName() != filename)
            {
                file->close();
                if (info.exists())
                {
                    QString dt = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
                    filename = info.absolutePath() + "/" +
                            info.bundleName() + dt + "." + info.suffix();
                }
                file->setFileName(filename);
            }
            if (!file->isOpen())
            {
                file->open(QIODevice::WriteOnly | QIODevice::Append);
            }
            if (file->isWritable())
            {
                file->write(content->data(), head->fileCurrentSize);
                if (head->currentProgress == 100)
                    file->close();
            }
            if (socketThread->isInterruptionRequested())
            {
                emit recvInformation(cn("接收终止"));
                file->close();
                socket->disconnectFromHost();
                socket->abort();
                socketThread->quit();
            }
            if (head->currentProgress == 100 && head->totalProgress == 100)
            {
                file->close();
                emit recvProgress(100, 1);
                emit recvInformation(cn("接收完成"));
                emit disconnected();
                socket->disconnectFromHost();
                socket->abort();
                socketThread->quit();
            }
        });

        connect(socket, &QTcpSocket::disconnected,
                this, [=] () {
            // disconnected
        });
        connect(socket, static_cast<void(QTcpSocket::*)(QAbstractSocket::SocketError)>(&QTcpSocket::error),
                this, [=] () {
            emit recvInformation(cn("接收终止"));
            emit disconnected();
            socketThread->quit();
        });
        connect(this, &ClientSocketOpt::senddata,
                this, [=] (QByteArray ba) {
            if (socket->state() != QAbstractSocket::ConnectedState)
                return;
            socket->write(ba);
            socket->waitForBytesWritten();
            socket->flush();
        });
        connect(socket, &QTcpSocket::readyRead,
                this, [=] () {
            // read data
            QByteArray ba = socket->readAll();
            recvCounts += ba.length();
            NetworkData nd(ba.data(), ba.length());
            deal->slotPosData(nd);
        });

        timerid = startTimer(1000);
    });
    socketThread->start();
}
开发者ID:AlanHJ,项目名称:TogetherHappy,代码行数:101,代码来源:clientsocketopt.cpp

示例12: ParseDataDomain

void QCmdParser::ParseDataDomain( QByteArray &data, QString& strInfo, qint8& nIndex )
{
    // data.length( ) >= 4

    qint32 nDomainLen = 4;

    if ( nDomainLen > data.length( ) ) {
        return;
    }

    qint32 nDI = data[ 0 ];
    nDI |= ( data[ 1 ] << 8 );
    nDI |= ( data[ 2 ] << 16 );
    nDI |= ( data[ 3 ] << 24 );

    data.remove( 0, nDomainLen );
    nDomainLen = data.length( );

    strInfo = "";

    switch ( nDI ) {
    case 0x04000300 :
        nIndex = 0;
        break;

    case 0x0400030C : // ƵÉÁ¹âÃô¿ØÖÆ
        GeLedtIlluminance( data, strInfo );
        nIndex = 1;
        break;

    case 0x04000301 : // ζÈ
        GetLedTemperature( data, strInfo );
        nIndex = 3;
        break;

    case 0x04000302 : // µÆ¹¤×÷״̬£¨00 =ƵÉÁ£»01=ÉÁ¹â£©Ä£Ê½
        GetLedWorkState( data, strInfo );
        nIndex = 4;
        break;

    case 0x04000303 : // ƵÉÁ´¥·¢·½Ê½£¨00=ÉÏÉýÑØ´¥·¢£»01=ϽµÑØ´¥·¢£»02=¸úËæģʽ£©Í¬²½
        GetLedFreqTriggerMode( data, strInfo );
        nIndex = 5;
        break;

    case 0x04000304 : // Êä³öÂö¿í0£¨°Ù·Ö±ÈÏÔʾ£©ÆµÉÁʱ¼ä
        GetLedFreqTime( data, strInfo );
        nIndex = 7;
        break;

    case 0x04000305 : // Êä³öÂö¿í1£¨°Ù·Ö±ÈÏÔʾ£©ÉÁ¹âʱ¼ä
        GetLedFlashTime( data, strInfo );
        nIndex = 8;
        break;

    case 0x04000306 : // Êä³öÂö¿í2£¨°Ù·Ö±ÈÏÔʾ£©ÆµÉÁÁÁ¶È
        GetLedFreqBrightness( data, strInfo );
        nIndex = 9;
        break;

    case 0x04000307 : // Êä³öÂö¿í3£¨°Ù·Ö±ÈÏÔʾ£©ÉÁ¹âÁÁ¶È
        GetLedFlashBrightness( data, strInfo );
        nIndex = 10;
        break;

    case 0x04000308 : // ƵÉÁƵÂÊ
        GetLedFrequency( data, strInfo );
        nIndex = 13;
        break;

    case 0x04000309 : // LEDµÆ¹¤×÷µçѹ
        GetLedWorkVoltage( data, strInfo );
        nIndex = 14;
        break;

    case 0x0400030A : // Íⲿ´¥·¢ÐźÅ״̬£¨00= Õý³££»01 = Òì³££©
        GetLedExternalTriggerSignalState( data, strInfo );
        nIndex = 15;
        break;

    case 0x0400030B : // ÉÁ¹â´¥·¢·½Ê½£¨00=ÉÏÉýÑØ´¥·¢£»01=ϽµÑØ´¥·¢£»02=¸úËæģʽ£©Í¬²½
        GetLedFlashTriggerMode( data, strInfo );
        nIndex = 6;
        break;

    case 0x0400030E : // ƵÉÁ¹âÃô·§Öµ
        GetThreshold( data, strInfo );
        nIndex = 11;
        break;

    case 0x0400030F : // ÉÁ¹â¹âÃô·§Öµ
        GetThreshold( data, strInfo );
        nIndex = 12;
        break;

    case 0x0400030D : // ÉÁ¹â¹âÃô¿ØÖÆ
        GeLedtIlluminance( data, strInfo );
        nIndex = 2;
        break;

//.........这里部分代码省略.........
开发者ID:Anne081031,项目名称:ParkCode,代码行数:101,代码来源:qcmdparser.cpp

示例13: createForeignWindow

bool HelloForeignWindowApp::createForeignWindow(const QString &group, const QString id, int x,
        int y, int width, int height)
{
    QByteArray groupArr = group.toAscii();
    QByteArray idArr = id.toAscii();

    // Window source rectangle.
    mRect[0] = 0;
    mRect[1] = 0;
    mRect[2] = width;
    mRect[3] = height;

    // You must create a context before you create a window.
    if (screen_create_context(&mScreenCtx, SCREEN_APPLICATION_CONTEXT) != 0) {
        return false;
    }

    // Create a child window of the current window group, join the window group and set
    // a window id.
    if (screen_create_window_type(&mScreenWindow, mScreenCtx, SCREEN_CHILD_WINDOW) != 0) {
        return false;
    }
    if (screen_join_window_group(mScreenWindow, groupArr.constData()) != 0) {
        return false;
    }
    if (screen_set_window_property_cv(mScreenWindow, SCREEN_PROPERTY_ID_STRING, idArr.length(),
            idArr.constData()) != 0) {
        return false;
    }

    // In this application we will render to a pixmap buffer and then blit that to
    // the window, we set the usage to native (default is read and write but we do not need that here).
    int usage = SCREEN_USAGE_NATIVE;
    if (screen_set_window_property_iv(mScreenWindow, SCREEN_PROPERTY_USAGE, &usage) != 0) {
        return false;
    }

    // The window size is specified in QML so we need to set up the buffer size to
    // correspond to that, the default size would be the full screen.
    if (screen_set_window_property_iv(mScreenWindow, SCREEN_PROPERTY_BUFFER_SIZE, mRect + 2) != 0) {
        return false;
    }
    if (screen_set_window_property_iv(mScreenWindow, SCREEN_PROPERTY_SOURCE_SIZE, mRect + 2) != 0) {
        return false;
    }

    // Use negative Z order so that the window appears under the main window.
    // This is needed by the ForeignWindow functionality.
    int z = -5;
    if (screen_set_window_property_iv(mScreenWindow, SCREEN_PROPERTY_ZORDER, &z) != 0) {
        return false;
    }

    // Set the window position on screen.
    int pos[2] = { x, y };
    if (screen_set_window_property_iv(mScreenWindow, SCREEN_PROPERTY_POSITION, pos) != 0) {
        return false;
    }

    // Finally create the window buffers, in this application we will only use one buffer.
    if (screen_create_window_buffers(mScreenWindow, 1) != 0) {
        return false;
    }

    // In this sample we use a pixmap to render to, a pixmap. This allows us to have
    // full control of exactly which pixels we choose to push to the screen.
    screen_pixmap_t screen_pix;
    if (screen_create_pixmap(&screen_pix, mScreenCtx) != 0) {
        return false;
    }

    // A combination of write and native usage is necessary to blit the pixmap to screen.
    usage = SCREEN_USAGE_WRITE | SCREEN_USAGE_NATIVE;
    if(screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_USAGE, &usage) != 0) {
        return false;
    }

    // Set the width and height of the buffer to correspond to the one we specified in QML.
    mSize[0] = width;
    mSize[1] = height;
    if (screen_set_pixmap_property_iv(screen_pix, SCREEN_PROPERTY_BUFFER_SIZE, mSize) != 0) {
        return false;
    }

    // Create the pixmap buffer and get a reference to it for rendering in the doNoise function.
    if (screen_create_pixmap_buffer(screen_pix) != 0) {
        return false;
    }
    if (screen_get_pixmap_property_pv(screen_pix, SCREEN_PROPERTY_RENDER_BUFFERS,
            (void **) &mScreenPixelBuffer) != 0) {
        return false;
    }

    // We get the stride (the number of bytes between pixels on different rows), its used
    // later on when we perform the rendering to the pixmap buffer.
    if (screen_get_buffer_property_iv(mScreenPixelBuffer, SCREEN_PROPERTY_STRIDE, &mStride) != 0) {
        return false;
    }

    return true;
//.........这里部分代码省略.........
开发者ID:bchilibeck,项目名称:Cascades-Samples,代码行数:101,代码来源:helloforeignwindowapp.cpp

示例14: addBrushPattern

int QPdfEnginePrivate::addBrushPattern(const QTransform &m, bool *specifyColor, int *gStateObject)
{
    int paintType = 2; // Uncolored tiling
    int w = 8;
    int h = 8;

    *specifyColor = true;
    *gStateObject = 0;

    QTransform matrix = m;
    matrix.translate(brushOrigin.x(), brushOrigin.y());
    matrix = matrix * pageMatrix();
    //qDebug() << brushOrigin << matrix;

    Qt::BrushStyle style = brush.style();
    if (style == Qt::LinearGradientPattern) {// && style <= Qt::ConicalGradientPattern) {
#ifdef USE_NATIVE_GRADIENTS
        *specifyColor = false;
        return gradientBrush(b, matrix, gStateObject);
#else
        return 0;
#endif
    }

    if ((!brush.isOpaque() && brush.style() < Qt::LinearGradientPattern) || opacity != 1.0)
        *gStateObject = addConstantAlphaObject(qRound(brush.color().alpha() * opacity),
                                               qRound(pen.color().alpha() * opacity));

    int imageObject = -1;
    QByteArray pattern = QPdf::patternForBrush(brush);
    if (pattern.isEmpty()) {
        if (brush.style() != Qt::TexturePattern)
            return 0;
        QImage image = brush.texture().toImage();
        bool bitmap = true;
        imageObject = addImage(image, &bitmap, qt_pixmap_id(brush.texture()));
        if (imageObject != -1) {
            QImage::Format f = image.format();
            if (f != QImage::Format_MonoLSB && f != QImage::Format_Mono) {
                paintType = 1; // Colored tiling
                *specifyColor = false;
            }
            w = image.width();
            h = image.height();
            QTransform m(w, 0, 0, -h, 0, h);
            QPdf::ByteStream s(&pattern);
            s << QPdf::generateMatrix(m);
            s << "/Im" << imageObject << " Do\n";
        }
    }

    QByteArray str;
    QPdf::ByteStream s(&str);
    s << "<<\n"
        "/Type /Pattern\n"
        "/PatternType 1\n"
        "/PaintType " << paintType << "\n"
        "/TilingType 1\n"
        "/BBox [0 0 " << w << h << "]\n"
        "/XStep " << w << "\n"
        "/YStep " << h << "\n"
        "/Matrix ["
      << matrix.m11()
      << matrix.m12()
      << matrix.m21()
      << matrix.m22()
      << matrix.dx()
      << matrix.dy() << "]\n"
        "/Resources \n<< "; // open resource tree
    if (imageObject > 0) {
        s << "/XObject << /Im" << imageObject << ' ' << imageObject << "0 R >> ";
    }
    s << ">>\n"
        "/Length " << pattern.length() << "\n"
        ">>\n"
        "stream\n"
      << pattern
      << "endstream\n"
        "endobj\n";

    int patternObj = addXrefEntry(-1);
    write(str);
    currentPage->patterns.append(patternObj);
    return patternObj;
}
开发者ID:NikhilNJ,项目名称:screenplay-dx,代码行数:85,代码来源:qprintengine_pdf.cpp

示例15: fm

void
TomahawkApp::init()
{
    if ( arguments().contains( "--help" ) || arguments().contains( "-h" ) )
    {
        printHelp();
        ::exit( 0 );
    }

    qDebug() << "TomahawkApp thread:" << thread();
    Logger::setupLogfile();
    qsrand( QTime( 0, 0, 0 ).secsTo( QTime::currentTime() ) );

    tLog() << "Starting Tomahawk...";

#ifdef ENABLE_HEADLESS
    m_headless = true;
#else
    m_mainwindow = 0;
    m_headless = arguments().contains( "--headless" );
    setWindowIcon( QIcon( RESPATH "icons/tomahawk-icon-128x128.png" ) );
    setQuitOnLastWindowClosed( false );

    QFont f = APP->font();
    f.setPixelSize( HeaderLabel::defaultFontSize() );
    QFontMetrics fm( f );
    TomahawkUtils::setHeaderHeight( fm.height() + 8 );
#endif

    TomahawkSettings* s = TomahawkSettings::instance();

    tDebug( LOGINFO ) << "Setting NAM.";
    // Cause the creation of the nam, but don't need to address it directly, so prevent warning
    Q_UNUSED( TomahawkUtils::nam() );

    m_audioEngine = QWeakPointer<AudioEngine>( new AudioEngine );
    m_scanManager = QWeakPointer<ScanManager>( new ScanManager( this ) );

    // init pipeline and resolver factories
    new Pipeline( this );

#ifndef ENABLE_HEADLESS
    Pipeline::instance()->addExternalResolverFactory( boost::bind( &QtScriptResolver::factory, _1 ) );
    Pipeline::instance()->addExternalResolverFactory( boost::bind( &ScriptResolver::factory, _1 ) );

    new ActionCollection( this );
    connect( ActionCollection::instance()->getAction( "quit" ), SIGNAL( triggered() ), SLOT( quit() ), Qt::UniqueConnection );
#endif

    m_servent = QWeakPointer<Servent>( new Servent( this ) );
    connect( m_servent.data(), SIGNAL( ready() ), SLOT( initSIP() ) );

    tDebug() << "Init Database.";
    initDatabase();

    QByteArray magic = QByteArray::fromBase64( enApiSecret );
    QByteArray wand = QByteArray::fromBase64( QCoreApplication::applicationName().toLatin1() );
    int length = magic.length(), n2 = wand.length();
    for ( int i=0; i<length; i++ ) magic[i] = magic[i] ^ wand[i%n2];
    Echonest::Config::instance()->setAPIKey( magic );

#ifndef ENABLE_HEADLESS
    tDebug() << "Init Echonest Factory.";
    GeneratorFactory::registerFactory( "echonest", new EchonestFactory );
#endif
    tDebug() << "Init Database Factory.";
    GeneratorFactory::registerFactory( "database", new DatabaseFactory );

    // Register shortcut handler for this platform
#ifdef Q_WS_MAC
    m_shortcutHandler = QWeakPointer<Tomahawk::ShortcutHandler>( new MacShortcutHandler( this ) );
    Tomahawk::setShortcutHandler( static_cast<MacShortcutHandler*>( m_shortcutHandler.data() ) );

    Tomahawk::setApplicationHandler( this );
    increaseMaxFileDescriptors();
#endif

    // Connect up shortcuts
    if ( !m_shortcutHandler.isNull() )
    {
        connect( m_shortcutHandler.data(), SIGNAL( playPause() ), m_audioEngine.data(), SLOT( playPause() ) );
        connect( m_shortcutHandler.data(), SIGNAL( pause() ), m_audioEngine.data(), SLOT( pause() ) );
        connect( m_shortcutHandler.data(), SIGNAL( stop() ), m_audioEngine.data(), SLOT( stop() ) );
        connect( m_shortcutHandler.data(), SIGNAL( previous() ), m_audioEngine.data(), SLOT( previous() ) );
        connect( m_shortcutHandler.data(), SIGNAL( next() ), m_audioEngine.data(), SLOT( next() ) );
        connect( m_shortcutHandler.data(), SIGNAL( volumeUp() ), m_audioEngine.data(), SLOT( raiseVolume() ) );
        connect( m_shortcutHandler.data(), SIGNAL( volumeDown() ), m_audioEngine.data(), SLOT( lowerVolume() ) );
        connect( m_shortcutHandler.data(), SIGNAL( mute() ), m_audioEngine.data(), SLOT( mute() ) );
    }

    tDebug() << "Init InfoSystem.";
    m_infoSystem = QWeakPointer<Tomahawk::InfoSystem::InfoSystem>( new Tomahawk::InfoSystem::InfoSystem( this ) );

    Echonest::Config::instance()->setNetworkAccessManager( TomahawkUtils::nam() );
#ifndef ENABLE_HEADLESS
    EchonestGenerator::setupCatalogs();


    if ( !m_headless )
    {
//.........这里部分代码省略.........
开发者ID:martgnz,项目名称:tomahawk,代码行数:101,代码来源:tomahawkapp.cpp


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