Important: Please read the Qt Code of Conduct -

How QTextDocumentWriter selects codec in textedit example?

  • I am trying the example in example/widgets/richitext in Windows.
    It can handle .txt, .md, and .html.
    When I save a Japanese document as txt, it is saved with UTF-8.
    When I save the same document as markdown(not html), it is saved with shift-JIS.
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    does not change the result.
    I would like to know the reason.

  • By the way, Window is Japanese edition.
    Build types are MSVC2019 and MinGW.

  • I solved by myself, maybe.
    In the constructor of TextEdit,
    textEdit = new QTextEdit(this);
    then I could save .md file as encoded by UTF-8.
    Without this, .md file will be saves as shift-jis (system's default).
    .txt files are always saved using UTF-8 encoding without the added line.

Log in to reply