有求必应

导航

qt字符数组转ASCII(十六进制)

接收网络传输数据

QByteArray  array;
//显示字符串 QString str = QString::fromLocal8Bit(array); m_receiveTxt.append(QString("%1:%2:%3").arg(m_TcpSocket->getIp()).arg(m_TcpSocket->getPort()).arg(str)); //显示十六进制 QString str = ascTohex(array); m_receiveTxt.append(QString("%1:%2:%3").arg(m_TcpSocket->getIp()).arg(m_TcpSocket->getPort()).arg(str));

 

//字符数组串转十六进制
QString Widget::ascTohex(QByteArray array)
{
    QString str = "";
    QString tem = array.toHex();
    for(int i = 0;i < tem.count();i++)
    {
        str.push_back(tem.at(i));
        if(i % 2 == 1 && i != 0)
        {
            str.push_back(' ');
        }
    }
    return str;
}

 

posted on 2019-03-12 17:14  名侦探江户川  阅读(5299)  评论(0编辑  收藏  举报