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. Set encoding for process output issue

Set encoding for process output issue

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.2k 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.
  • C Offline
    C Offline
    Cobra91151
    wrote on 11 Aug 2017, 08:42 last edited by
    #1

    Hi! I want to set encoding for cmd process for russian ouput. In C# the Process has StandardOutputEncoding function, in Qt such function does not exists.

    Here is the problem:

    0_1502440851569_2017-08-11_113955.png

    Any suggestion how to accomplish it?

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 11 Aug 2017, 08:58 last edited by
      #2

      http://doc.qt.io/qt-5/qtextstream.html#setCodec-1

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      C 1 Reply Last reply 11 Aug 2017, 09:26
      4
      • V Offline
        V Offline
        Vinod Kuntoji
        wrote on 11 Aug 2017, 09:03 last edited by
        #3

        @Cobra91151 ,

        Qt Provides Base64 encoding,

        C++, Qt, Qt Quick Developer,
        PthinkS, Bangalore

        C 1 Reply Last reply 11 Aug 2017, 09:20
        1
        • V Vinod Kuntoji
          11 Aug 2017, 09:03

          @Cobra91151 ,

          Qt Provides Base64 encoding,

          C Offline
          C Offline
          Cobra91151
          wrote on 11 Aug 2017, 09:20 last edited by
          #4

          @Vinod-Kuntoji

          Thanks but Base64 encoding doesn't work in my case.

          1 Reply Last reply
          0
          • V Offline
            V Offline
            Vinod Kuntoji
            wrote on 11 Aug 2017, 09:25 last edited by
            #5

            @Cobra91151 ,
            Can you show the sample code?

            C++, Qt, Qt Quick Developer,
            PthinkS, Bangalore

            1 Reply Last reply
            1
            • V VRonin
              11 Aug 2017, 08:58

              http://doc.qt.io/qt-5/qtextstream.html#setCodec-1

              C Offline
              C Offline
              Cobra91151
              wrote on 11 Aug 2017, 09:26 last edited by Cobra91151 8 Nov 2017, 09:27
              #6

              @VRonin

              I have tried setCodec to windows-1251, utf-8, cp1251, utf-16 but the same result:

              0_1502443496513_2017-08-11_122412.png

              void Test1::getData(QByteArray data)
              {
                  QTextStream encodeStream(data);
                  encodeStream.setCodec("windows-1251");
              
                  dataTextBrowser->append(encodeStream.readAll());
                  emit dataFinished();
              }
              
              1 Reply Last reply
              0
              • C Offline
                C Offline
                Cobra91151
                wrote on 11 Aug 2017, 09:33 last edited by Cobra91151 8 Nov 2017, 09:39
                #7

                Here is how in C# I have done it:

                private void myCMDEncoding()
                {
                     if (CultureInfo.CurrentUICulture.Name == "en-US")
                      {
                           myCMDProcess.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(437);
                      }
                
                      if (CultureInfo.CurrentCulture.Name == "ru-RU")
                      {
                            myCMDProcess.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866);
                      }
                
                      if (CultureInfo.CurrentCulture.Name == "uk-UA")
                      {
                           myCMDProcess.StartInfo.StandardOutputEncoding = Encoding.GetEncoding(866);
                      }
                }
                

                But now I need it for C++ in Qt.

                Console output:
                0_1502444338937_2017-08-11_123722.png

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Cobra91151
                  wrote on 11 Aug 2017, 14:50 last edited by
                  #8

                  I have fixed it by setting setCodec to IBM 866 and now it's working. Also, I included the code here, so others can find the solution.

                  void Test1::getData(QByteArray data)
                  {
                      QTextStream encodeStream(data);
                      encodeStream.setCodec("IBM 866");
                      dataTextBrowser->append(encodeStream.readAll());
                      emit dataFinished();
                  }
                  
                  1 Reply Last reply
                  1

                  1/8

                  11 Aug 2017, 08:42

                  • Login

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