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

QtCreator error could not decode with "UTF-8" Editing not possible.



  • Hello,
    on Ubuntu 16.04 my QtCreator 4.7.2 complains when editing files with locale carachters "èéàòì" even if they are into comments.

    This is the error:

    Error: Could not decode "filename.cpp" with "UTF-8"-encoding. Editing not possible.
    

    How can I solve that?
    TIA


  • Qt Champions 2019

    @Maruko Does the file contain valid UTF-8 text?



  • @jsulm I don't know.
    I have this problem wen I edit a file with another editor (i.e. gedit) inserting characters like "èéàòùì".
    When I do the same directly in QtCreator I don't have such problem.


  • Lifetime Qt Champion

    @Maruko

    You can run the command file filename.cpp to get more information about the encoding.

    Most likely the file was created on Windows and has Latin-1 encoding. However, Qt (and most modern compilers) requires sources files in UTF-8 encoding.

    Regards



  • @aha_1980
    thank you for the hint!

    The files without problems are
    C source, ASCII text, with CRLF line terminators

    The files not editable are
    C source, ISO-8859 text, with CRLF line terminators

    What do you suggest to do to unify every file in the same right way?


  • Lifetime Qt Champion

    Hi @Maruko,

    for encoding conversion in Linux this link gives a good overview. You can either convert it to UTF-8 (keeping all characters), or to pure ASCII, which means your characters will be replaced with the most similar ASCII character (e.g. é -> e).

    Please note, that CRLF line endings is also not the usual UNIX style, which can hurt you sooner or later.

    Git for example, let you checkout files on Windows with CRLF endings, while on Linux it gives only LF to maximise the interoperability.



  • I just discovered this because a header file from FTDI contained a copyright symbol. I just converted that to read (C) instead of the copyright symbol and it was fine.


Log in to reply