Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.12.3
-
None
-
-
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: