Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Is it possible to have superscript within the char* argument to the tr() function - particularily superscript 2(^2)?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved Language Bindings
8 Posts 3 Posters 3.0k Views 2 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.
  • C Offline
    C Offline
    CLang
    wrote on last edited by
    #1

    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)");

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • C Offline
        C Offline
        CLang
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          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.

          C Offline
          C Offline
          CLang
          wrote on last edited by
          #4

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

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

          1 Reply Last reply
          0
          • aha_1980A Offline
            aha_1980A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on last edited by aha_1980
            #5

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

            Qt has to stay free or it will die.

            C 1 Reply Last reply
            1
            • aha_1980A aha_1980

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

              C Offline
              C Offline
              CLang
              wrote on last edited by
              #6

              @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?

              aha_1980A 2 Replies Last reply
              0
              • C CLang

                @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?

                aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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 has to stay free or it will die.

                1 Reply Last reply
                0
                • C CLang

                  @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?

                  aha_1980A Offline
                  aha_1980A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  1

                  • Login

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