Решено: QtXml и кирилица (вопросики при разборе xml)

Модератор: Модераторы разделов

Аватара пользователя
fynjy
Сообщения: 172
ОС: openSuSE 11.2 i586

Решено: QtXml и кирилица

Сообщение fynjy »

Собственно имеется код в виде трёх файлов (все файлы имеют кодировку UTF-8):

Код:

//test.cpp #include <QtCore> #include <QtXml> class CContentHandler: public QXmlDefaultHandler { public: CContentHandler(QTextStream &aOut):iOut(aOut){}; protected: bool characters(const QString &ch); protected: QTextStream &iOut; }; bool CContentHandler::characters(const QString &ch) { iOut << "ch: [" << ch << "]\n"; return true; } int main(int /*argc*/, char** /*argv*/) { QXmlSimpleReader reader; QString str; QFile input("test.xml"); QFile output("out.txt"); QXmlInputSource source(&input); if (output.open(QFile::WriteOnly bitor QFile::Truncate)) { QTextStream out(&output); CContentHandler handler(out); out << "Привет мир!!!\n"; reader.setContentHandler(&handler); reader.parse(source); } return 0; } // test.pro QT += xml TEMPLATE = app SOURCES = test.cpp // test.xml <?xml version="1.0" encoding="UTF-8" ?> <zzz>Привет мир!!!</zzz>

После прогона появляется файл out.txt следующего содержания:

Код: Выделить всё

       Привет мир!!!
       ch: [?????? ???!!!]

Вопрос: откуда взялись знаки вопроса (символы с кодом 0x3F)? И как увидеть кирилицу в UTF-8 в out.txt?
Заранее, спасибо.

установлено openSuSE 11.1 x86_64 и qt 4.5.1

UPD. проблема решена. http://www.prog.org.ru/topic_9411_0.html
Спасибо сказали: