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. Umlauts in QString..

Umlauts in QString..

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 2.9k 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.
  • Z Offline
    Z Offline
    Zerby
    wrote on last edited by
    #1

    Hello,

    I've recently started making a GUI to my program with Qt. I like it so far, but I have one major problem. From the start up, I've had a translator file, which basicly holds a bunch of QString variables with the text I want. The main reason for this is to "easily" translate my program to English or other languages if needed. Text is Finnish at this point. For example, my header file:

    extern QString TEXT_UI_TITLE_ERROR_GENERAL_ERROR;
    extern QString TEXT_TITLE_TASKS_MAIN;

    source file:

    QString TEXT_UI_TITLE_ERROR_GENERAL_ERROR = "Virhe";
    QString TEXT_TITLE_TASKS_MAIN = " - Tehtävät";

    The problem is, I cannot get the umlauts to work (ä, ö..) at all. I've tried TEXT_TITLE_TASKS_MAIN.toLatin(), but that doesn't work. Is there any way to get this right? I've tried to Google and search all over, but no solution, driving me nuts. When I started I though "That can't be a big deal" and now that I've tried to resolve it it actually might not be that easy :P

    1 Reply Last reply
    0
    • A Offline
      A Offline
      akonradwesolutions
      wrote on last edited by
      #2

      You can try saving the source file containing your string using UTF8 encoding (any decent text editor / IDE should offer that option) and use

      @
      QString STR = QString::fromUtf8("Tehtävät");
      @

      What I actually would recommend is that you take a look at the translation support offered by Qt. You can mark all user-visible text in your application as translatable using
      @
      QObject::tr("Translatable String")
      @

      and use the lupdate and lrelease tools to create loadable translations for your UI.

      This should be a good starting point: https://qt-project.org/doc/qt-5.0/qtlinguist/qtlinguist-index.html

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        Zerby
        wrote on last edited by
        #3

        [quote author="Arnold Konrad" date="1365022562"]You can try saving the source file containing your string using UTF8 encoding (any decent text editor / IDE should offer that option) and use

        @
        QString STR = QString::fromUtf8("Tehtävät");
        @

        What I actually would recommend is that you take a look at the translation support offered by Qt. You can mark all user-visible text in your application as translatable using
        @
        QObject::tr("Translatable String")
        @

        and use the lupdate and lrelease tools to create loadable translations for your UI.

        This should be a good starting point: https://qt-project.org/doc/qt-5.0/qtlinguist/qtlinguist-index.html[/quote]

        Thank you for this, I will definetly look into that!

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          You could also try something like:
          @const wchar_t test = L"\xhhh";
          QString str = QString::fromUtf16((const ushort
          ) test);@

          ...where "hhh" is the Hex code for the character. Should work, even if your source code is Latin-1 encoded.

          But I'd also prefer the tr() method with Qt Linguist.

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          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