Qt 6.11 is out! See what's new in the release
blog
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 nosetCodecmethod 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
encodingattribute ifQT_NO_TEXTCODECis 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