Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Convert hexadecimal to decimal and vice-versa in Qt

From 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 00:30.
577 page views in the last 30 days.