Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to report an error in Qt doc? `QString::toDouble` doesn't support `QLocale`!

How to report an error in Qt doc? `QString::toDouble` doesn't support `QLocale`!

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 340 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xiedufang
    wrote on last edited by xiedufang
    #1

    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);, 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.

    aha_1980A 1 Reply Last reply
    1
    • X xiedufang

      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);, 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.

      aha_1980A Offline
      aha_1980A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Qt has to stay free or it will die.

      X 1 Reply Last reply
      2
      • aha_1980A aha_1980

        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

        X Offline
        X Offline
        xiedufang
        wrote on last edited by
        #3

        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.

        Regards

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved