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


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

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


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

示例1: decodePercentEncoding

/*
 * Decode URLs without doing any charset conversion.
 *
 * Most simple approach to do it without any lookahead.
 */
static QByteArray decodePercentEncoding(const QByteArray& input)
{
    int actualLength = 0;
    QByteArray tmpVal;
    QByteArray output;
    ParserState state = State_Begin;

    output.resize(input.length());
    tmpVal.resize(2);

    for (int i = 0; i < input.length(); ++i)
        if (state == State_Begin) {
            if (input.at(i) == '%') {
                state = State_FirstChar;
            } else {
                output[actualLength++] = input[i];
            }
        } else if (state == State_FirstChar) {
            state = State_SecondChar;
            tmpVal[0] = input[i];
        } else if (state == State_SecondChar) {
            state = State_Begin;
            tmpVal[1] = input[i];
            output[actualLength++] = tmpVal.toShort(0, 16);
        }

    output.resize(actualLength);
    return output;
}
开发者ID:jackiekaon,项目名称:owb-mirror,代码行数:34,代码来源:qwebnetworkinterface.cpp

示例2: GetThreshold

void QCmdParser::GetThreshold( QByteArray &data, QString &strInfo )
{
    QByteArray byHex = data.toHex(  );
    if ( 2 > byHex.count( ) ) {
        return;
    }

    qint8 cHigh = byHex.at( 0 );
    qint8 nLow = byHex.at( 1 );

    data.clear( );
    data.append( ( qint8 ) byHex.toShort( ) );

    strInfo.sprintf( "%c.%c", cHigh, nLow );
}
开发者ID:Anne081031,项目名称:ParkCode,代码行数:15,代码来源:qcmdparser.cpp

示例3:

/**@brief convert QString to 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::Str2Int_16(QByteArray str, unsigned short int * data)
{
    bool ok;
    *data = str.toShort(&ok, 16);
    return ok;
}
开发者ID:WuNL,项目名称:lab_workspace,代码行数:13,代码来源:Lms511Thread.cpp

示例4: transform


//.........这里部分代码省略.........
            case I8bits: {
                    quint8 val = 0;
                    memcpy(&val, temp.data(), integerSize);
                    output.append(QByteArray::number(val));
                    break;
            }
            case I16bits: {
                    quint16 val = 0;
                    memcpy(&val, temp.data(), integerSize);
                    output.append(QByteArray::number(val));
                    break;
            }
            case I32bits: {
                    quint32 val = 0;
                    memcpy(&val, temp.data(), integerSize);
                    output.append(QByteArray::number(val));
                    break;
            }
            case I64bits: {
                    quint64 val = 0;
                    memcpy(&val, temp.data(), integerSize);
                    output.append(QByteArray::number(val));
                    break;
            }
            }
        }
    } else {
        bool ok;
        char data[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

        if (signedInteger) {
            switch (integerSize) {
            case I8bits: {
                    qint16 val16 = input.toShort(&ok);
                    if (ok && val16 > -129 && val16 < 128) {
                        qint8 val8 = (qint8)val16;
                        memcpy(data, &val8, I8bits);
                    } else {
                        emit error(tr("Invalid 8bits signed Integer"),id);
                    }

                    break;
            }
            case I16bits: {
                    qint16 val16 = input.toShort(&ok);
                    if (ok) {
                        memcpy(data, &val16, I16bits);
                    } else {
                        emit error(tr("Invalid 16bits signed Integer"),id);
                    }
                    break;
            }
            case I32bits: {
                    qint32 val32 = input.toInt(&ok);
                    if (ok) {
                        memcpy(data, &val32, I32bits);
                    } else {
                        emit error(tr("Invalid 32bits signed Integer"),id);
                    }
                    break;
            }
            case I64bits: {
                    qint64 val64 = input.toInt(&ok);
                    if (ok) {
                        memcpy(data, &val64, I64bits);
                    } else {
开发者ID:pipacker10,项目名称:pip3line,代码行数:67,代码来源:bytesinteger.cpp


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