[Qt-creator] "Editing not possible" solution

Frédéric Marchal frederic.marchal at wowtechnology.com
Wed Jan 21 07:20:16 CET 2015


2015-01-20 23:48 GMT+01:00 Pawel <pawelfaron87 at wp.pl>:
> Hello,
>
> In my company we work in multinational teams. Many people uses strange file
> encodings and they don't plan to change it...
> In QtCreator I quite often see the "Editing not possible" error. I know that
> file decoding is a difficult subject, but I'm sure we can do better than
> this.
>
> I've implemented simple code to help a bit. It is located in
> textdocument.cpp, and differs from current solution with:
>
> - [Current solution] In functions read() when decoding with default codec
> fails we return error.
> - [My Solution] In functions read() when decoding with default codec fails I
> try all available codecs (QTextCodec::availableCodecs()), and if any one
> success I return success.
>
> What do you think about this?

It's very likely not going to work:
http://en.wikipedia.org/wiki/Charset_detection

"Character encoding detection, charset detection, or code page
detection is the process of heuristically guessing the character
encoding of a series of bytes that represent text. The technique is
recognized to be unreliable[...]".

Many character encodings cannot be distinguished except by the fact
that the text, when decoded with the wrong encoding, looks like
gibberish to a human reader.

It is not possible to automate it.

What would be more reasonable is to have one fallback encoding when
UTF-8 fails and a BOM was expected.

Without BOM, it is unreliable and would fail if the file contains some
characters from another character set but that happen to match valid
UTF-8 sequences. In that case, the file would be wrongly opened as
UTF-8.

Frederic



More information about the Qt-creator mailing list