Important: Please read the 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:

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

    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: - 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