Is it possible to have superscript within the char* argument to the tr() function - particularily superscript 2(^2)?



  • The superscript text can exist in VS within the editor. The tr() function returns a diamond '?'

    I have tried using unicode: \u00B2

    Is there a way to have a superscript within the argument?

    For Example:
    QString plotYAxis = tr("Emission Factor(g/m²h)");


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What version of Qt are you using ?
    On what OS ?
    With which compiler ?

    Your string works for me on macOS 10.12 with Qt 5.10.1.



  • This post is deleted!


  • @SGaist (Not sure if I replied or just posted the first time)

    Hi Sorry. It's QT 5.5 on Windows using MSVC 2013.


  • Qt Champions 2017

    @CLang I guess it works for @SGaist as he runs on macOS, and there the source file is encoded in UTF-8 (like on Linux too). The compiler on the other hand, expects the source file to be in UTF-8 and converts the string from UTF-8 to UTF-16 (the internal representation of QString).

    On Windows, things are much more complicated. On my system (Western Europe) Visual Studio assumes the source files to be Latin-1 encoded, and that is true for a lot of C++ source files indeed. On the other hand, tr() expects the char * to be UTF-8 encoded.

    You may be able to convice Visual Studio to treat your source files as UTF-8 encoded, but that means you can only edit them with Editors that are UTF-8 aware afterwards.

    I personally didn't go this way, but encoded the special characters with HTML tricks: tr("ö"); outputs "ö".

    If you want to translate your applications anyway, you can avoid the special chars in source code and only add them in the translations. That should always work.

    Regards.



  • @aha_1980 Thanks for the reply. That makes sense.

    I am a little confused at your suggestion for HTML tricks:

    I tried your example and the QString = "ö" - Is this due to my region?

    On the last line, are you suggesting to edit the .ts file with the superscript characters?


  • Qt Champions 2017

    @CLang said in Is it possible to have superscript within the char* argument to the tr() function - particularily superscript 2(^2)?:

    @aha_1980 Thanks for the reply. That makes sense.

    I am a little confused at your suggestion for HTML tricks:

    I tried your example and the QString = "ö" - Is this due to my region?

    If you see 'ö' then all is fine :) -> o with umlaut

    On the last line, are you suggesting to edit the .ts file with the superscript characters?

    exactly. as the .ts file is always UTF-8 this should work. however, you then need to load the translation in your code.


  • Qt Champions 2017

    @CLang

    I now tried your example with HTML: it would look like this:

    QString plotYAxis = tr("Emission Factor(g/m<sup>2</sup>h)");

    and I got this nicely rendered on a QLabel.


Log in to reply
 

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