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. [SOLVED] Encoding troubles
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Encoding troubles

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.1k Views 1 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.
  • P Offline
    P Offline
    phobos8
    wrote on last edited by
    #1

    [SOLVED]

    Hi,

    i have troubles with encoding. In my app there is a QGraphicsView, and when i click on one of menu buttons it creates a new QGraphicsTextItem inside of QGraphicsView. A problem is that some czech characters don't show properly, there are crazy symbols instead of the right ones .. but another part off app is, when i rightclick created QGraphicsTextItem and choose Edit from shown context menu, my app shows text editor where i can edit a text shown in my QGraphicsTextItem and when i use czech characters like ěščřžýáíé, everything works ... My problem is that i need to have some text including czech characters when QGraphicsTextItem is initialized and I cannot find a solution..

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      How do you initialize the default text in your source code? Is the source file encoded in UTF-8?

      (Z(:^

      1 Reply Last reply
      0
      • P Offline
        P Offline
        phobos8
        wrote on last edited by
        #3

        QString tip="Text můžete upravit pomocí kontextového menu položky.";
        text = new myQGraphicsTextItem(tip);

        every file in my project is in UTF-8, in qt this text looks like above, but when i press ctrl+R and run app and click to create a new QGraphicsTextItem, then it shows crazy characters instead of ů.ž,é and ž in the last word.
        I had same problem when i initialized it as text = new myQGraphicsTextItem("Text můžete upravit pomocí kontextového menu položky."); .. tried to set text into a QString, cuz QString should contain UTF-8 text, but it makes no difference for me ..

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          @
          QString tip=QStringLiteral(“Text můžete upravit pomocí kontextového menu položky.”);
          // or
          QString tip(trUtf8(“Text můžete upravit pomocí kontextového menu položky.”));
          @

          I'm not sure any of those would help, source text encoding can be a PITA. I think there are also some compiler flags that you can use to force it to use an encoding.

          (Z(:^

          1 Reply Last reply
          0
          • P Offline
            P Offline
            phobos8
            wrote on last edited by
            #5

            the second one

            @ QString tip(trUtf8(“Text můžete upravit pomocí kontextového menu položky.”));@

            works well for me, thanks a lot :)

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Hi,
              Maybe add this:
              @CODECFORSRC = UTF-8@
              to your pro file. That will setup the default way of coding the source files
              also your QString init is a bit C, not C++. Use the constructors available to create a QString(....); not QString = ....

              Greetz, Jeroen

              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