Nominate our 2022 Qt Champions!

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(, 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(, 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;
    d = QString("1234,56").toDouble(&ok);   // ok == false
    d = QString("1234.56").toDouble(&ok);   // ok == true, d == 1234.56
    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);, the QString("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.

  • Lifetime Qt Champion

    Hi @xiedufang,

    thanks for your report. Indeed, the comment is wrong. I therefore prepared a doc update:

    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.


  • Hi @aha_1980,
    thanks for the quick reply.

    It's ok if it will be fixed in the future.

    I will mark this topic as solved.


Log in to reply