Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] UTF-8 and special character decoding

[SOLVED] UTF-8 and special character decoding

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 2 Posters 3.9k Views
  • 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.
  • A Offline
    A Offline
    AlterX
    wrote on 18 Dec 2014, 10:41 last edited by
    #1

    Hello,
    I am getting crazy...I tried a lot of suggestions from internet without success!
    I have a string, coming from internet and when I print out it, i have this:
    @
    qDebug()<< "received UTF-8 text: " << QString::fromUtf8(text);
    @

    Output of above instruction is:
    received UTF-8 text: Test \u003c \u003e

    this escape characters are html tags ( < > )

    all my file are UTF-8 (set from within QtCreator) this problem is in a .cpp file, even though qlm TextEdit is not able to manage it and show correct string!

    Someone knows how to resolve this problem?

    Qt Ambassador
    Real-time cooperative teams: http://www.softairrealfight.net
    Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

    https://codereview.qt-project.org/...

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 18 Dec 2014, 11:50 last edited by
      #2

      What is text variable in the snippet? Is it a QByteArray, char* or another QString?

      (Z(:^

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AlterX
        wrote on 18 Dec 2014, 12:10 last edited by
        #3

        Ah sorry...QString(char *)
        I know that the above constructor can be a problem dealing with utf, but unfortunately I didn't find a solution.

        Qt Ambassador
        Real-time cooperative teams: http://www.softairrealfight.net
        Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

        https://codereview.qt-project.org/...

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 18 Dec 2014, 12:18 last edited by
          #4

          I would try with QString::fromUtf16() and QString::fromRawData(). Maybe one of them would work.

          (Z(:^

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AlterX
            wrote on 18 Dec 2014, 12:21 last edited by
            #5

            Ok thanks I will give a try

            Qt Ambassador
            Real-time cooperative teams: http://www.softairrealfight.net
            Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

            https://codereview.qt-project.org/...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AlterX
              wrote on 18 Dec 2014, 13:58 last edited by
              #6

              I am printing this in cpp file using qDebug and then I assign this text to a qml TextEdit...and it dispalys on android exactly that string with escape characters...unbelievable!

              Qt Ambassador
              Real-time cooperative teams: http://www.softairrealfight.net
              Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

              https://codereview.qt-project.org/...

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AlterX
                wrote on 19 Dec 2014, 13:34 last edited by
                #7

                I found a solution and I write it down just to help others in case:
                @
                QTextCodec *codec = QTextCodec::codecForName("ISO 8859-1");

                QString asciiString = codec->fromUnicode(text);
                @

                Qt Ambassador
                Real-time cooperative teams: http://www.softairrealfight.net
                Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

                https://codereview.qt-project.org/...

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sierdzio
                  Moderators
                  wrote on 19 Dec 2014, 13:48 last edited by
                  #8

                  Great, thank you for sharing!

                  (Z(:^

                  1 Reply Last reply
                  0

                  2/8

                  18 Dec 2014, 11:50

                  topic:navigator.unread, 6
                  • Login

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