PDA

View Full Version : int to String Conversion



aj2903
4th December 2009, 13:00
hi...

i'm having some doubt regarding conversion of int to string.

Suppose



int iAscii_Val =65;
//As 65 in Ascii represents 'A'
QString strAscii = iAscii_Val;



Is there any method to convert so that i can get "A" in strAscii[QString] ?

Lykurg
4th December 2009, 13:04
See the docs to QChar.

BrainB0ne
4th December 2009, 22:09
@aj2903
see this little piece of code :)



int iAscii_Val = 65;
QString strAscii = QChar(iAscii_Val).toAscii();

Lykurg
4th December 2009, 22:22
What's new in your answer? But anyway, it makes no sens to convert the QChar to char before assigning it to a QString, since QString will convert it back. So this conversion is useless.

BrainB0ne
4th December 2009, 22:43
What's new in your answer? But anyway, it makes no sens to convert the QChar to char before assigning it to a QString, since QString will convert it back. So this conversion is useless.

You are absolutely right :)

it should be:


int iAscii_Val = 65;
QString strAscii = QChar(iAscii_Val);


The reason I answered was just to be helpful for other people that are struggling with it ( and now have some cut 'n' paste code they can use :) )