[Qt-interest] QString::toInt
Scott Aron Bloom
Scott.Bloom at onshorecs.com
Mon Sep 5 19:59:52 CEST 2011
To put it more clearly...
The default value for base is 10, not 0.
If you want it to "auto detect" you must EXPLICTLY set base to 0
qDebug() << QString( "0xFF" ).toInt( NULL, 0 );
Works like a charm
Scott
From: qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com
[mailto:qt-interest-bounces+scott.bloom=onshorecs.com at qt.nokia.com] On
Behalf Of nandita-a.mehta at nokia.com
Sent: Monday, September 05, 2011 1:14 AM
To: qt-interest at qt.nokia.com
Subject: [Qt-interest] QString::toInt
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.
However this is not the case.
QString str2 = "0xFF";
qDebug()<<str2.toInt(); //0 zero
QString str3 = "0789";
qDebug()<<str3.toInt(); //789
bool ok;
qDebug()<<str2.toInt(&ok, 16);//255
Any clarification what does above sentence mean?
Thanks,
Nandita
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110905/f0b5db81/attachment.html
More information about the Qt-interest-old
mailing list