Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. unable to decode utf-8 characters

unable to decode utf-8 characters

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 4 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
    Pradeep Reddy
    wrote on last edited by
    #1

    Hi, I am trying to read data from text file which is in German language and writing data to sqlite, on desktop everything is working as expected, but on android it is displaying unknown characters (eg: nyomvonal elt�rS impulzusok) .
    std::string strInput;
    std::getline(m_pInputFile, strInput);

        QString sLine;
        char *pStr = ( char *)strInput.c_str();
        QByteArray encodedString =  pStr;
        nStr = QString::fromUtf8(encodedString);
        if(nStr.toUtf8() != encodedString)
            nStr = QString::fromLatin1(encodedString);
    

    qDebug() << "nStr" << nStr ;

    Above debug is printing correct text on desktop on android it is not. Any solution highly appreciate.

    jsulmJ 1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Don't know if this is the cause of the problem, but "nyomvonal elt�rS impulzusok" isn't German, but Hungarian I'd guess.

      1 Reply Last reply
      1
      • P Pradeep Reddy

        Hi, I am trying to read data from text file which is in German language and writing data to sqlite, on desktop everything is working as expected, but on android it is displaying unknown characters (eg: nyomvonal elt�rS impulzusok) .
        std::string strInput;
        std::getline(m_pInputFile, strInput);

            QString sLine;
            char *pStr = ( char *)strInput.c_str();
            QByteArray encodedString =  pStr;
            nStr = QString::fromUtf8(encodedString);
            if(nStr.toUtf8() != encodedString)
                nStr = QString::fromLatin1(encodedString);
        

        qDebug() << "nStr" << nStr ;

        Above debug is printing correct text on desktop on android it is not. Any solution highly appreciate.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Pradeep-Reddy Is the string show correctly in the app? This could be just an encoding problem with the terminal.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        P 2 Replies Last reply
        0
        • jsulmJ jsulm

          @Pradeep-Reddy Is the string show correctly in the app? This could be just an encoding problem with the terminal.

          P Offline
          P Offline
          Pradeep Reddy
          wrote on last edited by
          #4

          @jsulm no it is not displaying correctly ..
          @Wieland .. ya its not German but the problem is there other than English

          J.HilkJ 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Pradeep-Reddy Is the string show correctly in the app? This could be just an encoding problem with the terminal.

            P Offline
            P Offline
            Pradeep Reddy
            wrote on last edited by
            #5

            @jsulm basically i observed the difference
            on Desktop QString::fromUtf8(encodedString) is returning proper text.
            but on Android QString::fromUtf8(encodedString) it is returning unknown characters...

            1 Reply Last reply
            0
            • P Pradeep Reddy

              @jsulm no it is not displaying correctly ..
              @Wieland .. ya its not German but the problem is there other than English

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Pradeep-Reddy
              You should check if your char-array actually contains the correct UTF chars or not.

              That said, why do you use std for reading a textfile if your application after that runs in/with Qts own libaries?

              Read text file line by line with Qt link


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              P 1 Reply Last reply
              0
              • J.HilkJ J.Hilk

                @Pradeep-Reddy
                You should check if your char-array actually contains the correct UTF chars or not.

                That said, why do you use std for reading a textfile if your application after that runs in/with Qts own libaries?

                Read text file line by line with Qt link

                P Offline
                P Offline
                Pradeep Reddy
                wrote on last edited by
                #7

                @J.Hilk hi .. i am sure the char array is having utf-8 data ..
                i am usinf std file stream because if files are with big size .. seeking is not working perfectly if i used with Qfile and QTextStream .

                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