View Full Version : QString to hex

21st December 2009, 12:54
how can ı convert fron QString to hex ?

21st December 2009, 13:21
by RTFM!

I mean, really! why not first look in the documentation?

QString QString::arg ( int a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' ) ) const

This function overloads arg().

The a argument is expressed in base base, which is 10 by default and must be between 2 and 36. For bases other than 10, a is treated as an unsigned integer.

fieldWidth specifies the minimum amount of space that a is padded to and filled with the character fillChar. A positive value produces right-aligned text; a negative value produces left-aligned text.

The '%' can be followed by an 'L', in which case the sequence is replaced with a localized representation of a. The conversion uses the default locale, set by QLocale::setDefault(). If no default locale was specified, the "C" locale is used. The 'L' flag is ignored if base is not 10.

QString str;
str = QString("Decimal 63 is %1 in hexadecimal")
.arg(63, 0, 16);
// str == "Decimal 63 is 3f in hexadecimal"

QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates));
str = QString("%1 %L2 %L3")
.arg(12345, 0, 16);
// str == "12345 12,345 3039"