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. [SOLVED] - QString and encoding (UTF-8)
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] - QString and encoding (UTF-8)

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 5.1k 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
    maximus
    wrote on 14 Feb 2014, 19:17 last edited by
    #1

    Hi,

    I'm creating an object that has multiple QString, I would like them to support UTF-8 character (for example Chinese, russian, etc.)

    I have a web service that returns some database field as utf-8 (xml file with utf-8 format)
    Here is a real example:
    http://maximumtrainer.com/phprestsql/?username=max3&password=123&lang=fr&getUser=1
    Check for <first_name> and <last_name> for example of UTF-8 varchar

    When I am parsing this xml in QT, the chinese and russian character show as ???? instead of the real value, I have tested with french character (éèâ, etc.) and those works. Any idea why the other one are not shown, is it the qDebug console that is not utf-8 ? is it QString that is not utf-8 ?

    The parsing is not the the problem, because if I set directly the QString value to chinese character, I cannot display it in the console, example :
    @user->first_name = "喜喜";
    qDebug() << "USER FIRST NAME? IS " << user->first_name;@

    Thanks if you can give me a hand


    Free Indoor Cycling Software - https://maximumtrainer.com

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JKSH
      Moderators
      wrote on 15 Feb 2014, 03:26 last edited by
      #2

      Hi,

      [quote]
      @user->first_name = "喜喜";@
      [/quote]You usually cannot put unicode strings in your source code directly -- your compiler might not understand it.

      You need to use "Unicode string literals":http://stackoverflow.com/questions/7636797/unicode-string-literals, which was introduced in C++11.

      [quote]
      @qDebug() << "USER FIRST NAME? IS " << user->first_name;@
      [/quote]I'm not 100% sure, but I think qDebug() uses your system's console. Windows' console cannot print Unicode.

      You can try writing to a QLabel or a QFile instead.

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dbzhang800
        wrote on 15 Feb 2014, 14:54 last edited by
        #3

        Hi, you need to make sure that your compiler support utf8 executable charset if you want to use raw Chinese string literals. Though this is not a problem for most compilers, but MSVC have very bad support for utf8 exec-charset.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maximus
          wrote on 17 Feb 2014, 02:32 last edited by
          #4

          I guess the problem is the console/Windows, like you said JKSH
          If I ouput the result in a QLabel, it is displayed correctly
          @ QString str = "喜喜";
          ui->label_user->setText(str);@

          I'll go code on Ubuntu now :)

          Thanks for your input guys,


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply
          0

          1/4

          14 Feb 2014, 19:17

          • Login

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