//实现
QString Widget::hexToString(QByteArray DataArray)
{
QString str;
for(int i = 0; i< DataArray.length(); i++)
{
QString byteStr = QString::number(static_cast<uchar>(DataArray[i]), 16);
if(byteStr.length() == 1)
{
str += "0" + byteStr;
}
else
{
str += byteStr;
}
}
qDebug()<<str;
}
//测试
void Widget::on_pushButton_clicked()
{
QByteArray array;
array.push_back(0x01);
array.push_back(0x02);
array.push_back(0x03);
array.push_back(0x04);
hexToString(array);
}
测试输出
"0x01020304"