Namespaces
Variants
Actions

Convert hexadecimal to decimal and vice-versa in Qt

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

Article
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.png
Note: 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.
796 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved