Revision as of 03:30, 21 January 2013 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Convert hexadecimal to decimal and vice-versa in Qt

From Nokia Developer Wiki
Jump to: navigation, search

These code snippets shows how to convert hexadecimal to decimal unsigned integer, and vice versa.

Conversion from Hexadecimal to Integer and vice-versa is frequently required in Qt, for example if you want to show UID of application to user then you will get it in uint form, so need to convert in hexadecimal. Similarly when you want to uninstall application silently, then you need to convert hexadecimal to integer, because XQInstaller::remove() method take UID in integer form, not in hexadecimal.

Article Metadata
Created: savaj (22 Jun 2009)
Last edited: hamishwillee (21 Jan 2013)

Hexadecimal to decimal conversion

/* hexadecimal 0xED8788DC is equivavelent to decimal 3985082588 */
QString str = "0xED8788DC";
bool ok;
uint appId = str.toUInt(&ok,16); //appId contains 3985082588

Decimal to hexadecimal conversion

/* decimal 3985082588 is equivalent to hex ED8788DC */
uint decimal = 3985082588;
QString hexadecimal;
haxadecimal.setNum(decimal,16); //now hexadecimal contains ED8788DC

Note.pngNote: There is a brief overview of how to convert between decimal and hex manually here: how to convert hex to decimal

This page was last modified on 21 January 2013, at 03:30.
482 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.