Umlauts in QString..



  • 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



  • 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 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!



  • 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.