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. Output funky UTF-8 to console
Forum Updated to NodeBB v4.3 + New Features

Output funky UTF-8 to console

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.7k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    Moschops
    wrote on last edited by
    #1

    I have a console program that uses various QT classes. It needs to be translatable into Japanese.

    I am pretty sure my terminal is showing such glyphs correctly, as I have a directory named 我能吞下玻璃而 that quite happily appears in my Gnome terminal.

    I thought I'd start by making one of the QStrings inside the console contain some of these characters, and just see if I can get them all the way out to the console. I cannot :(

    The QString is question is created like this:
    @const QString Message_Location(QObject::tr(" 形声文字 of : "));@

    It is then passed to a QTextStream& object, m_output;
    @ m_output << Message_Location << endl;@

    m_output seems to be a reference to a QTextStream object created like this in an initialiser list:
    @m_stdOutput(stdout, QIODevice::WriteOnly)@

    The output I actually get in the console is:
    @形声文字 of@
    although on my console some of that is those little rectangles with numbers in that one gets when something's gone wrong with the character handling.

    Right before this line executes:
    @ m_output << Message_Location << endl;@
    I can use the debugger and see that Mesasge_Location is a QString containing the value @形声æ\226\207å­\227 of@

    I really don't know where to look first for something like this. Can anyone help?

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, if you are running your console program on Windows, you will find displaying UTF-8 difficult in some programs , like the CMD console and Notepad. Due to age they do not understand UTF-8.
      Suggest you try another operating system :-)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Moschops
        wrote on last edited by
        #3

        I'm using Gnome terminal in Ubuntu.

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          Hi,

          You need 3 things:

          • Your .cpp file needs to be saved as a UTF-8-encoded file
          • You must write your code using "UTF-8 string literals":http://en.wikipedia.org/wiki/C++11#New_string_literals
          • You must enable C++11 support in your compiler

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          • Login

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