Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Umlauts in QString..

    General and Desktop
    3
    4
    2633
    Loading More Posts
    • 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
      Zerby last edited by

      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 Reply Quote 0
      • A
        akonradwesolutions last edited by

        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 Reply Quote 0
        • Z
          Zerby last edited by

          [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 Reply Quote 0
          • M
            MuldeR last edited by

            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 Reply Quote 0
            • First post
              Last post