Qt 6 introduced the QStringConverter
class as a replacement for the Qt 5 QTextCodec
class. QTextCodec
is deprecated in Qt 6 and only available as part of the core5compat
compatibility module. QTextCodec
will probably be removed in Qt 7.
Now, QTextCodec
supported a whole lot of different text encodings (see here), but QStringConverter
only supports the most common Unicode text encodings and ISO-8859-1 (see here). However, legacy text encodings like e.g. CP-1252 are still needed today to decode text files from the pre-Unicode era.
So, how can I continue to use any of these text encodings in Qt 6? Is the Qt 5 compatibility module really the only way?
As of Qt 6.6 QStringConverter can now be constructed for any codec support by ICU. And it is possible to see available ICU codecs. Unfortunately Qt still has not updated classes like QTextStream to accept anything other than the predetermined enum set supported directly by qt itself. QTBUG-109254 purposes to fix this but appears stalled. When Qt6 came out designers made the strange choose to go to a hard coded list of supported codecs. The ICU backend is supported but optional from Qts perspective thus requiring direct checks for this library.