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

How QTextDocumentWriter selects codec in textedit example?



  • I am trying the example textedit.pro 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.
    Adding,
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    writer.setCodec(codec);
    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,
    after
    textEdit = new QTextEdit(this);
    add
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
    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