Qdebug display hex value

2019-06-15 00:32发布

I am trying to display a number using QDebug in the Hex format. Below is the code which I have written. It is working but the output has string contents enclosed in double quotes:

How to remove these quotes?

m_CanMsg_ptr->id = 0x720;
m_CanMsg_ptr->sizeData = 1;
m_CanMsg_ptr->data[0] = 0x05;

MessageID.setNum(m_CanMsg_ptr->id,16);
DataSize  = QString("%1").arg(m_CanMsg_ptr->sizeData, 0, 16);
data      = QString("%1").arg(m_CanMsg_ptr->data[0], 0, 16)

qDebug() << "Heart-Beat : Msg ID = " << MessageID << "  Msg DLC = " << DataSize;
qDebug() << "Msg Data " << " = " << data;

I did as per these resources:

http://forum.qt.io/topic/5003/moved-how-to-display-a-local-variable-in-hex-when-debugging-a-qt-app/2 http://qt.shoutwiki.com/wiki/Convert_hexadecimal_to_decimal_and_vice-versa_in_Qt

enter image description here

标签: qt qdebug
9条回答
够拽才男人
2楼-- · 2019-06-15 01:05

The solution is simple:

#include <QDebug>

int value = 0x12345;
qDebug() << "Value : " << hex << value;
查看更多
老娘就宠你
3楼-- · 2019-06-15 01:07
qDebug() << QByteArray::number(myNumber).toHex()
查看更多
Emotional °昔
4楼-- · 2019-06-15 01:15
int value = 0xff005542;
qDebug() << QString("%1").arg(value , 0, 16).toUpper()

>>> FF005542

查看更多
登录 后发表回答