Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved QProcess does not recognize input path with accent

    General and Desktop
    qprocess c++ windows10
    4
    8
    515
    Loading More Posts
    • 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.
    • X
      xchess64 last edited by xchess64

      Hello,

      I have two programs each with QProcess and I have a different behavior concerning the QProcess input with accentuated characters
      (more precisely I create a Qprocess to execute a dos copy command and the path takes accent).

      The environnement of execution and development is Windows 10.

      The first program is a simple prototype that I made to test if my code can work correctly.

      Here is the prototype code I have, in which the copy works correctly, integrated in a simple main() function.
      The code is supposed to copy a file named sfx.exe into a path with accent F:\path_accentué and it indeed does the copy correctly.

      #include <QCoreApplication>
      #include <Qdebug>
      #include <QObject>
      #include <QProcess>
      #include <QDir>
      #include <wtypes.h>
      #include <winbase.h>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication app(argc, argv);
          QProcess* processus = new QProcess();
          QStringList args; 
          QString path("F:\\path_accentué");
          
          args << "/C" << "copy" << "E:\\test\\sfx.exe" << path;
          processus->start("cmd.exe", args);  
      
          if (!processus->waitForStarted())
          {
              qDebug() << "Could not launch the process";
          }
          //processus->write(s.c_str());
          if (!processus->waitForFinished(-1))
          {
              qDebug() << "Finished";
          }
          delete processus;
          return app.exec();
      }
      

      However, when I integrate (literally copies and pasted without changing) this prototype within a bigger code project, my instance of QProcess does not recognize the accentuated path, as if accents are no more supported.

      This is the part that I copy/paste in the bigger project and which I now execute via a button click in QT.
      And this time, the QProcess doesn't recognize the accentuated path (sometimes it creates a file with name like this path_accentu�

                  QProcess* processus = new QProcess();
                  QStringList args; 
                  QString path("F:\\path_accentué");
                  args << "/C" << "copy" << "E:\\test\\sfx.exe" << path;            
                  processus->start("cmd.exe", args);  
                  if (!processus->waitForStarted())
                  {
                              qDebug() << "Could not launch the process";
                  }
                  //processus->write(s.c_str());
                  if (!processus->waitForFinished(-1))
                  {
                              qDebug() << "Finished";
                  }
      

      I do not find in the documentation a way to force the QProcess to recognize accentuated inputs.
      I would like to understand why the QProcess instance behaves differently when integrated within a bigger project.
      What may impact the behavior of the QProcess and leads it to treat differently the input in the second case?

      I thank you in advance for your help.

      jsulm JonB 2 Replies Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @xchess64 last edited by

        @xchess64 Is the source code file encoded as UTF-8?

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

        X 1 Reply Last reply Reply Quote 3
        • JonB
          JonB @xchess64 last edited by

          @xchess64
          I don't know why the difference, I would suspect something about codecs/code pages/locales different in the big program?

          But just before you start investigating: is your problem/need to use QProcess only for this "DOS copy command"? Because unless you need it for all sorts of other commands, I wouldn't copy a file via some QProcess command anyway. So if that's all you could save yourself a lot of grief... :)

          X 1 Reply Last reply Reply Quote 0
          • X
            xchess64 @JonB last edited by

            @JonB Thanks guys for the response.
            Indeed, the QProcess is needed for more things (such as getting feedback and percentage of operations). The copy is only to isolate the problem. In reality, I do much more things.

            1 Reply Last reply Reply Quote 2
            • X
              xchess64 @jsulm last edited by

              @jsulm
              I have checked, Indeed the example code is encoded in UTF-8 and the code of my bigger project is encoded in ANSI. This may explain why it works in the first cas and not in the second case.
              Remark: I may not be allowed to change the encoding of the bigger project.

              JonB 1 Reply Last reply Reply Quote 0
              • JonB
                JonB @xchess64 last edited by JonB

                @xchess64 said in QProcess does not recognize input path with accent:

                Remark: I may not be allowed to change the encoding of the bigger project.

                Then --- and I never know the exact code for this! --- do you need to not put a literal accentuated-character (é) into your source code file but instead use whatever it is which correctly encodes the desired character (like some \x...)? @jsulm ?

                jsulm 1 Reply Last reply Reply Quote 1
                • jsulm
                  jsulm Lifetime Qt Champion @JonB last edited by jsulm

                  @JonB I don't think so, as encoding is ANSI which is 7bit. But I'm not sure.

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

                  1 Reply Last reply Reply Quote 0
                  • Christian Ehrlicher
                    Christian Ehrlicher Lifetime Qt Champion last edited by

                    @JonB: yes, and then use QString::fromUtf8()

                    Qt has to stay free or it will die.

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post