PDA

View Full Version : converting string to unsigned integer



mgurbuz
11th May 2006, 13:18
Hi,
Does anybody know how to convert "-2" string to integer?
I have tried doing it as follows but no success....
Is there anything wrong with the following code???

QString s = "-2";

bool ok;

uint m = s.toUInt( &ok, 10 );

Thank you for any help...

mgurbuz
11th May 2006, 13:23
We figured out how to do it....Here it goes....

QByteArray bArray = s.toLatin1();

const char * ch = bArray.constData();

int m = atoi(ch);

If there is anyother way your welcome to let me know...

Thanks....



Hi,
Does anybody know how to convert "-2" string to integer?
I have tried doing it as follows but no success....
Is there anything wrong with the following code???

QString s = "-2";

bool ok;

uint m = s.toUInt( &ok, 10 );

Thank you for any help...

jpn
11th May 2006, 13:36
uint m = s.toUInt( &ok, 10 );
How about asking for and storing the result in a signed integer aswell? :)

int m = s.toInt( &ok, 10 );

wysota
12th May 2006, 00:12
Tell me, how would you like to store a negative number as an unsigned integer? :D As 2^32 - 2? :) Or maybe 2^31? AFAIK -2 is a signed integer...

mgurbuz
12th May 2006, 09:46
Allright I got it....

I was tried and didn't really read what I wrote....
and tried many things at that time from toUInt ... to... toInt
couldn't make it work.
My question was how to convert a string to signed integer
and as an expert you understand it perfectly....


Tell me, how would you like to store a negative number as an unsigned integer? :D As 2^32 - 2? :) Or maybe 2^31? AFAIK -2 is a signed integer...