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. Got off the encoding
QtWS25 Last Chance

Got off the encoding

Scheduled Pinned Locked Moved General and Desktop
15 Posts 3 Posters 6.8k 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.
  • R Offline
    R Offline
    Ruzik
    wrote on last edited by
    #1

    Hellow, i have some problem:
    if a try to do it:
    @textEdit->append(process->readAllStandardOutput());@
    //process is object of QProcess
    i get it:
    bq. “áâ ­®¢ª á¢ï§¨ á CORBINA...
    à®¢¥àª ¨¬¥­¨ ¨ ¯ à®«ï ¯®«ì§®¢ ⥫ï...
    ¥£¨áâà æ¨ï ª®¬¯ìîâ¥à ¢ á¥â¨...
    “áâ ­®¢«¥­ á¢ï§ì á CORBINA.
    Š®¬ ­¤ ãᯥ譮 § ¢¥à襭 .

    behind normal text, i try use toAscii(), toLocal8bit(), toUtf8(), toLatin1(), but i dont get normal text, how can i do it?
    Advance many thanks for your help!

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

      The problem is probably not in the conversion from QString, but in the conversion to QString. The QProcess::readALlStandardOutput() function returns a byte array. You have to convert that to a QString using the proper encoding using one of the QString::from*() variants, or even explicitly stating an encoding. Probably you could go for QString::fromLocal8Bit(), but I'm not sure about that.

      What kind of text does the process output?

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on last edited by
        #3

        @Franzk
        Seems like russian text in win cp1251 (or, oh god, cp 866) encoding :D

        @Ruzik try toLocal8bit() to local QString, after it try using QTextCodec class for correct encoding

        --
        Vasiliy

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruzik
          wrote on last edited by
          #4

          I try use all QString::from*, but it is donr work

          bq. What kind of text does the process output?

          I think, that it is must output russian text, as think Vass

          bq. Ruzik try toLocal8bit() to local QString, after it try using QTextCodec class for correct encoding

          I try do it, but i get other strange simbols instead of normal signs:
          @ QString str;
          QByteArray bArray = process->readAllStandardOutput();
          str = QString(bArray).toLocal8Bit();
          QTextCodec * tc = QTextCodec::codecForLocale();
          if(tc->canEncode(str))
          textEdit->append(tc->toUnicode(bArray));@

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #5

            [quote]
            @ QString str;
            QByteArray bArray = process->readAllStandardOutput();
            str = QString(bArray).toLocal8Bit();
            QTextCodec * tc = QTextCodec::codecForLocale();
            if(tc->canEncode(str))
            textEdit->append(tc->toUnicode(bArray));@
            [/quote]
            You are worried about the outgoing encoding, but you forget the incoming encoding. This code makes no sense at all.

            Get your incoming encoding right:

            @ // untested
            QTextCodec *codec = QTextCodec::codecForLocale();
            QByteArray bytes = process->readAllStandardOutput();
            QString str = codec->toUnicode(bytes);
            textEdit->append(str);
            @

            While you're at it, check if codecForLocale() is actually the codec you need.

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Ruzik
              wrote on last edited by
              #6

              bq. While you’re at it, check if codecForLocale() is actually the codec you need.

              It seems that no,

              “бв ­®ўЄ бўп§Ё б CORBINA...
              Џа®ўҐаЄ Ё¬Ґ­Ё Ё Ї а®«п Ї®«м§®ў ⥫п...
              ђҐЈЁбва жЁп Є®¬ЇмовҐа ў бҐвЁ...
              “бв ­®ў«Ґ­ бўп§м б CORBINA.
              Љ®¬ ­¤ гбЇҐи­® § ўҐа襭 .

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Franzk
                wrote on last edited by
                #7

                That of course implied that you find out what encoding the external process uses to output it's text. Does it look OK when you run the application in a console? Does the application documentation say anything about it?

                "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • R Offline
                  R Offline
                  Ruzik
                  wrote on last edited by
                  #8

                  Process - rasdial.exe in Windows(http://msdn.microsoft.com/en-us/library/aa377004(v=vs.85).aspx )
                  Output on the russian language(on the my computer), but i dont know encoding of this process

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    Franzk
                    wrote on last edited by
                    #9

                    There is a slight possibility that that program outputs utf16 encoded data. Just using the byte array won't bu sufficient then. I'm not sure how to find out whether it does, though.

                    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      Ruzik
                      wrote on last edited by
                      #10

                      bq. I’m not sure how to find out whether it does, though

                      I try to ask it by Microsoft))

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Ruzik
                        wrote on last edited by
                        #11

                        Microsoft didnt get me answer, i think that Vass was right, it is CP1251(Windows-1251)

                        1 Reply Last reply
                        0
                        • R Offline
                          R Offline
                          Ruzik
                          wrote on last edited by
                          #12

                          I found that it is may CP1251 or koi8-U

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Franzk
                            wrote on last edited by
                            #13

                            Consider choosing that locale explicitly:

                            @QTextCodec *cp1251 = QTextCodec::codecForName("Windows-1251");
                            QTextCodec *koi8u = QTextCodec::codecForName("KOI8-U");
                            @
                            for example, and see if that makes a difference in converting the string to unicode/QString.

                            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                            http://www.catb.org/~esr/faqs/smart-questions.html

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              Ruzik
                              wrote on last edited by
                              #14

                              Yes, it makes a difference in converting the string to unicode/QString
                              Windows-1251:
                              “бв ­®ў«Ґ­ бўп§м б CORBINA.
                              Љ®¬ ­¤ гбЇҐи­® § ўҐа襭 .

                              Koi8-U
                              ⌠АБ═ґ╝╒╚╔ґ═ А╒ОїЛ А CORBINA.
                              ┼╝╛═ґє═ ЦА╞╔Хґ╝ ї═╒╔ЮХ╔ґ═.

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                Ruzik
                                wrote on last edited by
                                #15

                                I find it, it was CP866
                                Many thanks for your help!

                                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