Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-80068

QDomDocument always uses system locale settings while writing double numbers

    XMLWordPrintable

Details

    • All
    • d7cb21ac085117f879a8aa1d7727b2ca52d3353d (qt/qtbase/5.14)

    Description

      I have tried to write down float and double numbers to xml file. But there is a problem:
      float numbers always writing with dot decimal separator and double numbers wtiteing with comma seperator even if programm locale set to QLocale::C.

      Thera two variables:
      float floatVal = 0.1234f;
      double doubleVal = 0.1234;

      When I wtite them to QDomDocument the output file looks like this:
       
      <Root doubleVal="0,1234" floatVal="0.1234"/>

       System locale settings are:

      // 
      user@paefimov:~$ locale
      LANG=en_US.UTF-8
      LANGUAGE=en_US
      LC_CTYPE="en_US.UTF-8"
      LC_NUMERIC=ru_RU.UTF-8
      LC_TIME=en_US.UTF-8
      LC_COLLATE="en_US.UTF-8"
      LC_MONETARY=ru_RU.UTF-8
      LC_MESSAGES="en_US.UTF-8"
      LC_PAPER=ru_RU.UTF-8
      LC_NAME=ru_RU.UTF-8
      LC_ADDRESS=ru_RU.UTF-8
      LC_TELEPHONE=ru_RU.UTF-8
      LC_MEASUREMENT=ru_RU.UTF-8
      LC_IDENTIFICATION=ru_RU.UTF-8
      LC_ALL=
      

      Example:

      // 
      #include <QCoreApplication>
      
      #include <QDomDocument>
      #include <QFile>
      #include <QTextStream>
      #include <QDebug>
      
      int main(int argc, char* argv[])
      {
          QCoreApplication a(argc, argv);
      
          QLocale locale(QLocale::C);
      
          QLocale::setDefault(locale);
      
          QFile xmlFile("data.xml");
          xmlFile.open(QIODevice::WriteOnly);
      
          QDomDocument xmlWriter;
      
          QDomElement rootNode = xmlWriter.createElement("Root");
          xmlWriter.appendChild(rootNode);
      
          float floatVal = 0.1234f;
          double doubleVal = 0.1234;
      
          rootNode.setAttribute("DecimalPoint", locale.decimalPoint());
          rootNode.setAttribute("floatVal", floatVal);
          rootNode.setAttribute("doubleVal", doubleVal);
      
          xmlFile.write(xmlWriter.toByteArray());
          xmlFile.close();
      
          return a.exec();
      }
      

      The Qt Forum topic is here:

      https://forum.qt.io/topic/108853/qdomdocument-always-uses-system-locale-settings-while-writing-double-numbers-in-linux

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            chehrlic Christian Ehrlicher
            tetsuzin72 Pavel Efimov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes