How to report an error in Qt doc? `QString::toDouble` doesn't support `QLocale`!
-
Qt 5.15 Doc.
In the doc of
double QString::toDouble(bool *ok = nullptr) const
(https://doc.qt.io/qt-5/qstring.html#toDouble), it says:The string conversion will always happen in the 'C' locale. For locale dependent conversion use QLocale::toDouble()
.But in the doc of
class QLocale
(https://doc.qt.io/qt-5/qlocale.html#details), a piece of example code looks like this:QLocale::setDefault(QLocale(QLocale::Hebrew, QLocale::Israel)); QLocale hebrew; // Constructs a default QLocale QString s1 = hebrew.toString(15714.3, 'e'); bool ok; double d; QLocale::setDefault(QLocale::C); d = QString("1234,56").toDouble(&ok); // ok == false d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 QLocale::setDefault(QLocale::German); d = QString("1234,56").toDouble(&ok); // ok == true, d == 1234.56 d = QString("1234.56").toDouble(&ok); // ok == true, d == 1234.56 QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedStates)); str = QString("%1 %L2 %L3") .arg(12345).arg(12345).arg(12345, 0, 16); // str == "12345 12,345 3039"
After
QLocale::setDefault(QLocale::German);
, theQString("1234,56")
handles comma as decimal point, which is NOT right.There is a conflict between the example code & the doc of
QString::toDouble
. After a test, I found the example code invalid. -
Hi @xiedufang,
thanks for your report. Indeed, the comment is wrong. I therefore prepared a doc update: https://codereview.qt-project.org/c/qt/qtbase/+/310516
However, it seems a bit more work is involved as the file was renamed for Qt 6 and patches need to go there first. So it may take some time until 5.15.x is fixed.
Regards