开发者

QXmlStreamWriter and cyrillic

I have a problem with encoding when writing XML files via QXmlStreamWriter in windows, how can I resolve it? Using stream.setCodec("UTF-8") or "windows-1251" is not helped.

QFile *file = new QFile(filename);
if (file->open(QIODevice::WriteOnly | QIODevice::Text))
         {
         QXmlStreamWriter stream(file);
         stream.setAutoFormatting(true);
         stream.writeStartDocument();
         stream.writeStartElement("СЕКЦИЯ"); // start root section
            stream.writeStartElement("FIELD");
            stream.writeAttribute("name", "Имя");
            stream.writeAttribute("value", "Иван");
     开发者_如何学JAVA       stream.writeEndElement();
         stream.writeEndElement(); // END СЕКЦИЯ
         file->close();
}


Most likely the interpretation of the string literals in your source file is the problem, not the configuration of the stream writer. Make sure your source file is encoded in UTF-8 and use QString::fromUtf8("Imja") etc. (Imja in cyrillic of course) instead of the implicit literal to QString conversion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜