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


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

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


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

示例1:

void tAt5PreAtlas::CreateEncryptionKeys(QIODevice& device, boost::shared_ptr< tChPreAtlasHdr > xPreAtlas,
                                        boost::shared_ptr< tChAtlasHdr> xAtlasHdr, 
                                        QString typeStr, QString serialNum, std::vector<ulong>& keyList)
{
    tAt5Stream stream;
    tChPreAtlasHdr* pPreAtlas = xPreAtlas.get();
    if (!pPreAtlas)
        return;

    tChAtlasHdr* pAtlasHdr = xAtlasHdr.get();
    if (!pAtlasHdr)
        return;

    tAt5AtlasVersion atlas_version = pAtlasHdr->GetAt5Version();

    // Now build Signature string
    std::vector<uchar> Signature;

    // Add type string to Signature
    QByteArray tmpAsciiStr = typeStr.toAscii();
    for (int ts = 0; ts < tmpAsciiStr.size(); ts++)
        Signature.push_back(tmpAsciiStr[ts]);

    // Add serial number
    for (int sn = 0; sn < serialNum.size(); sn+= 2)
    {
        QByteArray arr;
        arr.append(serialNum[sn].toAscii());
        arr.append(serialNum[sn+1].toAscii());
        uchar sigChar = (uchar) arr.toUShort(0, 16);
        Signature.push_back(sigChar);
    }

    // Add Atlas checksum
    Signature.insert(Signature.end(), (uchar*)&(pPreAtlas->AtlasHdrCksum.m_Val) , ((uchar*)&(pPreAtlas->AtlasHdrCksum.m_Val)+2));

    // Add last byte of map.
    ulong LastCartPos = pPreAtlas->DataSize() + pPreAtlas->AtlasCartPos.m_Val + pPreAtlas->AtlasDataLen.m_Val - 1;
    stream.InsStrm(device, atlas_version.m_MajorAtlasVer, atlas_version.m_MinorAtlasVer, LastCartPos, 1);
    tCdUchar LastChar;
    stream >> LastChar;
    Signature.push_back(LastChar.m_Val);

    ulong AckStart = pPreAtlas->AtlasCartPos.m_Val + pPreAtlas->DataSize() + pPreAtlas->AtlasHdrLen.m_Val + 
        pAtlasHdr->AcknowledgeListPos.m_Val;

    stream.ClearBuff();
    if (pAtlasHdr->AcknowledgeListLen.m_Val != 0)
    {
        stream.InsStrm(device, atlas_version.m_MajorAtlasVer, atlas_version.m_MinorAtlasVer, AckStart, pAtlasHdr->AcknowledgeListLen.m_Val);

        for (uint ackIndex = 0; ackIndex < pAtlasHdr->AcknowledgeListLen.m_Val; ++ackIndex)
        {
            tCdUchar ackChar;
            stream >> ackChar;
            Signature.push_back(ackChar.m_Val);
        }
    }
开发者ID:dulton,项目名称:53_hero,代码行数:58,代码来源:At5ChPreAtlasHdr.cpp

示例2:

/**@brief convert QString to unsigned short int (2 bytes, 16 bits);
 *
 *@param str [IN]: the string to convert;
 *@param data [OUT]: the result is stored in this parm;
 *@return bool, if convert succeed, return true; else, return false;
 *@note
 */
bool Lms511Thread::Str2Uint_16(QByteArray str, unsigned short int *data)
{
    bool ok;
    *data = str.toUShort(&ok, 16);
    return ok;
}
开发者ID:WuNL,项目名称:lab_workspace,代码行数:13,代码来源:Lms511Thread.cpp

示例3: QVariant

bool
Field::setDefaultValue(const QByteArray& def)
{
    if (def.isNull()) {
        m_defaultValue = QVariant();
        return true;
    }

    bool ok;
    switch (type()) {
    case Byte: {
        unsigned int v = def.toUInt(&ok);
        if (!ok || v > 255)
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(v);
        break;
    }
    case ShortInteger: {
        int v = def.toInt(&ok);
        if (!ok || (!(m_options & Unsigned) && (v < -32768 || v > 32767)) || ((m_options & Unsigned) && (v < 0 || v > 65535)))
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(v);
        break;
    }
    case Integer: {//4 bytes
        long v = def.toLong(&ok);
//js: FIXME   if (!ok || (!(m_options & Unsigned) && (-v > 0x080000000 || v > (0x080000000-1))) || ((m_options & Unsigned) && (v < 0 || v > 0x100000000)))
        if (!ok || (!(m_options & Unsigned) && (-v > (int)0x07FFFFFFF || v > (int)(0x080000000 - 1))))
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant((qint64)v);
        break;
    }
    case BigInteger: {//8 bytes
//! @todo BigInteger support
        /*
              qint64 long v = def.toLongLong(&ok);
        //TODO: 2-part decoding
              if (!ok || (!(m_options & Unsigned) && (-v > 0x080000000 || v > (0x080000000-1))))
                m_defaultValue = QVariant();
              else
                if (m_options & Unsigned)
                  m_defaultValue=QVariant((quint64) v);
                else
                  m_defaultValue = QVariant((qint64)v);*/
        break;
    }
    case Boolean: {
        unsigned short v = def.toUShort(&ok);
        if (!ok || v > 1)
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant((bool)v);
        break;
    }
    case Date: {//YYYY-MM-DD
        QDate date = QDate::fromString(def, Qt::ISODate);
        if (!date.isValid())
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(date);
        break;
    }
    case DateTime: {//YYYY-MM-DDTHH:MM:SS
        QDateTime dt = QDateTime::fromString(def, Qt::ISODate);
        if (!dt.isValid())
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(dt);
        break;
    }
    case Time: {//HH:MM:SS
        QTime time = QTime::fromString(def, Qt::ISODate);
        if (!time.isValid())
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(time);
        break;
    }
    case Float: {
        float v = def.toFloat(&ok);
        if (!ok || ((m_options & Unsigned) && (v < 0.0)))
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(v);
        break;
    }
    case Double: {
        double v = def.toDouble(&ok);
        if (!ok || ((m_options & Unsigned) && (v < 0.0)))
            m_defaultValue = QVariant();
        else
            m_defaultValue = QVariant(v);
        break;
    }
    case Text: {
        if (def.isNull() || (uint(def.length()) > maxLength()))
            m_defaultValue = QVariant();
//.........这里部分代码省略.........
开发者ID:crayonink,项目名称:calligra-2,代码行数:101,代码来源:field.cpp


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