Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How QTextDocumentWriter selects codec in textedit example?
QtWS25 Last Chance

How QTextDocumentWriter selects codec in textedit example?

Scheduled Pinned Locked Moved Solved General and Desktop
richtextcodecwriter
3 Posts 1 Posters 328 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yoshiTBL
    wrote on 16 Nov 2020, 03:54 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • Y Offline
      Y Offline
      yoshiTBL
      wrote on 16 Nov 2020, 04:12 last edited by
      #2

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

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        yoshiTBL
        wrote on 16 Nov 2020, 11:32 last edited by
        #3

        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.

        1 Reply Last reply
        0

        3/3

        16 Nov 2020, 11:32

        • Login

        • Login or register to search.
        3 out of 3
        • First post
          3/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved