[Qt-interest] QString::toInt
Andreas Pakulat
apaku at gmx.de
Mon Sep 5 14:38:48 CEST 2011
On 05.09.11 08:13:48, nandita-a.mehta at nokia.com wrote:
> Hi,
>
> In the documentation http://doc.qt.nokia.com/latest/qstring.html#toInt ,it is mentioned
>
> "If base is 0, the C language convention is used: If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used."
>
> I understand from the above sentence that if the string begins with "0x" then base 16 is used implicitly while if the string begins with 0 base 8 is used implicitly.
Only if 0 is passed as base parameter.
> However this is not the case.
>
> QString str2 = "0xFF";
> qDebug()<<str2.toInt(); //0 zero
>
> QString str3 = "0789";
> qDebug()<<str3.toInt(); //789
Thats because your not passing a base-parameter value, hence its taking
the default values which means base=10. So the function works correctly.
Also not 0789 is not a valid octal number, so you'd get 0 back if you
convert that using base=8.
Andreas
More information about the Qt-interest-old
mailing list