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 quot
Use noquote()
to avoid the quotation marks. As in:
qDebug().noquote() << QString::number(value, 16);
May be a little late, but in case someone needs this:
As statet in the answere by Kuber Ober, Qt only removes the quotes if it's a const char *
passed to qDebug
. However, Qt provides a macro to do the same with a QString
- The qPrintable
macro:
qDebug() << qPrintable(QString("String without quotes")) << QString("String with quotes");
This way, you can use the QString::number
function (as provided by TheDancinZerg) to format the string:
int value = 0xFFFF;
qDebug() << qPrintable(QString::number(value, 16));
int value = 0xff005542;
qDebug() << QString("%1").arg(value , 0, 16).toUpper();
>>> FF005542
That'll give you hex output at whatever length is required. But if you'd like fixed width output, this is handy (example of four hex digits):
int value = 0xff;
qDebug() << QString("%1").arg(value, 4, 16, (QChar)'0').toUpper();
// Here's the fixed field length⬆︎
>>> 00FF