Qdebug display hex value

The solution is simple:

#include <QDebug>

int value = 0x12345;
qDebug() << "Value : " << hex << value;

You could format string first:

int myValue = 0x1234;
QString valueInHex= QString("%1").arg(myValue , 0, 16);
qDebug() << "value = " << valueInHex;

Another way of doing this would be:

int value = 0xFFFF;
qDebug() << QString::number(value, 16);

Hope this helps.

Edit: To remove the quotes you can cast the number as a pointer, as qt will format that without using quotes. For instance:

int value = 0xFFFF;
qDebug() << (void *) value;  

Slightly hackish, but it works.

Tags:

Qt

Qdebug