Re: convert Qstring into int
Hi sabbu,
You can try it :
Code:
bool convertOK;
unsigned long int n = ui->lineEdit()->text().toULong(&convertOK);
if(!convertOK) return -1;
:)
Re: convert Qstring into int
A 32bit (which is probably what you use) unsigned int can only store values till 4.294.967.295. So you should use a long or something that can handle such large numbers.
Re: convert Qstring into int
You can try this -
Code:
bool ok;
long no = sss.toLong(&ok,10);
Re: convert Qstring into int
let me guess, you are working on a 64bit system. To ensure, that your code is working everywhere one probably should use q(u)int64.
EDIT: Eh, you should stay with the thread starters number! 1234567809 != 9990540087 and 1234567809 is small enough to get into a 32 bit signed integer!
Re: convert Qstring into int
yes i am using 64 bit system
Code:
bool ok;
quint64 no = str.toLong(&ok,10);
it is working fine.
Re: convert Qstring into int
sir,
i could not success i am tired.My operting system is 32 bit. when i convert a string 10 digit number find only 0 .if i convert string 9 digit number i find 9 digit .i use all below code but i am not success.please help me
1.bool ok;
2.QString str = "9990540087";
3.quint64 no = str.toLong(&ok,10);
///////////////////////////////////
1.bool convertOK;
2.unsigned long int n = ui->lineEdit()->text().toULong(&convertOK);
3.if(!convertOK) return -1;
//////////////
1. bool ok;
2.QString str = "9990540087";
3.long no = sss.toLong(&ok,10);
Re: convert Qstring into int
Use this, you need 64 bit number, with 32 bit unsigned you get a max of 4294967295, but you use number larger than this.
Code:
quint64 number = str.toULongLong();
or
qulonglong number = str.toULongLong();
//or even str.toLongLong() signed version will also work for a typical 10-digit number
Re: convert Qstring into int
Thanks ,
this code is work for me.