Details
-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
None
-
5.12.8, 5.15.0
-
None
-
Windows 10 x64, MSVC 2019 + Windows 10 x64, MSVC 2017
Description
When you try to write XML and use non-utf8 encoding XML become broken - tags and attributes names are blank, values too.
This code
#include <QCoreApplication> #include <QXmlStreamWriter> #include <QFile> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QString s = "α фетопротеин"; // utf-8 string qDebug().noquote() << s << endl; QFile file("bug.xml"); if(!file.open(QIODevice::Text | QIODevice::WriteOnly)) return -1; QXmlStreamWriter sw(&file); sw.setAutoFormatting(true); sw.setAutoFormattingIndent(-1); sw.setCodec("WINDOWS-1251"); sw.writeStartDocument("1.0"); sw.writeStartElement("ROOT"); sw.writeAttribute("CORRECT", QString::fromLocal8Bit(s.toLocal8Bit())); // replaces "α" character with "?" sw.writeAttribute("BUGGED", s); // should be ? mark instead of "α" character but it is "" and from now on every other tag/attribute looks like ="" and <></> for(int i = 0; i < 3; i++) { sw.writeStartElement("SUBTAG"); sw.writeAttribute("BUGGED2", s); for(int j = 0; j < 3; j++) { sw.writeStartElement("SUBTAG_TOO"); sw.writeAttribute("BUGGED_TOO", "correct ansi string"); sw.writeEndElement(); } sw.writeEndElement(); } sw.writeEndElement(); // ROOT sw.writeEndDocument(); file.close(); return a.exec(); }
produce this file
<?xml version="1.0" encoding="windows-1251"?> <ROOT CORRECT="? фетопротеин" BUGGED=""> < =""> < =""/> < =""/> < =""/> </> < =""> < =""/> < =""/> < =""/> </> < =""> < =""/> < =""/> < =""/> </> </>