Solved QXmlStreamReader Codec
-
Noob question here:
Does QXmlStreamReader auto detect the text codec based on the start document (<?xml version="1.0" encoding="UTF-8"?>
)? I noticed there is nosetCodec
method while QXmlStreamWriter has it so I want to make 100% sure it's dealt with automatically. -
Hi! Yes, the codec is automatically set depending on the
encoding
attribute ifQT_NO_TEXTCODEC
is not defined. See qxmlstream.cpp:#ifdef QT_NO_TEXTCODEC readBuffer = QString::fromLatin1(rawReadBuffer.data(), nbytesread); #else QTextCodec *const newCodec = QTextCodec::codecForName(name.toLatin1()); if (!newCodec) err = QXmlStream::tr("Encoding %1 is unsupported").arg(name); else if (newCodec != codec && !lockEncoding) { codec = newCodec; delete decoder; decoder = codec->makeDecoder(); decoder->toUnicode(&readBuffer, rawReadBuffer.data(), nbytesread); } #endif // QT_NO_TEXTCODEC
-
Hi! Yes, the codec is automatically set depending on the
encoding
attribute ifQT_NO_TEXTCODEC
is not defined. See qxmlstream.cpp:#ifdef QT_NO_TEXTCODEC readBuffer = QString::fromLatin1(rawReadBuffer.data(), nbytesread); #else QTextCodec *const newCodec = QTextCodec::codecForName(name.toLatin1()); if (!newCodec) err = QXmlStream::tr("Encoding %1 is unsupported").arg(name); else if (newCodec != codec && !lockEncoding) { codec = newCodec; delete decoder; decoder = codec->makeDecoder(); decoder->toUnicode(&readBuffer, rawReadBuffer.data(), nbytesread); } #endif // QT_NO_TEXTCODEC