Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Automatic input encoding detection for Qt?



  • While working with my text editor(*), I tried to implement the same sort of automatic input encoding detection system I have in my Python version. It detects input encoding using encoding errors:

    [code]
    decodings = [ "utf-8", "latin-1" ]
    def decode(self, content):
    for codec in self.decodings:
    try:
    content = unicode(content, codec)
    except UnicodeDecodeError:
    continue
    return content
    raise Exception("Unknown encoding: " + filename)
    [/code]

    I searched Qt documentation, but I was not able to find out, how to detect encoding errors with QTextStream. Is there any way to detect the input file encoding with Qt?

    (*) Now it can be found at gitorious: https://gitorious.org/moe - it is not exactly ready for co-operative development, but I try to fix the problems.



  • Ping for this, should automatically detecting UTF8 and ANSI encoding at least,


Log in to reply