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
Forum Updated to NodeBB v4.3 + New Features

Set encoding for process output issue

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 2.4k 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on 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
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on 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

      Cobra91151C 1 Reply Last reply
      4
      • Vinod KuntojiV Offline
        Vinod KuntojiV Offline
        Vinod Kuntoji
        wrote on last edited by
        #3

        @Cobra91151 ,

        Qt Provides Base64 encoding,

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

        Cobra91151C 1 Reply Last reply
        1
        • Vinod KuntojiV Vinod Kuntoji

          @Cobra91151 ,

          Qt Provides Base64 encoding,

          Cobra91151C Offline
          Cobra91151C Offline
          Cobra91151
          wrote on last edited by
          #4

          @Vinod-Kuntoji

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

          1 Reply Last reply
          0
          • Vinod KuntojiV Offline
            Vinod KuntojiV Offline
            Vinod Kuntoji
            wrote on last edited by
            #5

            @Cobra91151 ,
            Can you show the sample code?

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

            1 Reply Last reply
            1
            • VRoninV VRonin

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

              Cobra91151C Offline
              Cobra91151C Offline
              Cobra91151
              wrote on last edited by Cobra91151
              #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
              • Cobra91151C Offline
                Cobra91151C Offline
                Cobra91151
                wrote on last edited by Cobra91151
                #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
                • Cobra91151C Offline
                  Cobra91151C Offline
                  Cobra91151
                  wrote on 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

                  • Login

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