本文整理汇总了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;
}
示例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 );
}
示例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;
}
示例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 {