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. QProcess does not recognize input path with accent
Forum Update on Monday, May 27th 2025

QProcess does not recognize input path with accent

Scheduled Pinned Locked Moved Unsolved General and Desktop
qprocessc++windows10
8 Posts 4 Posters 1.1k 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.
  • X Offline
    X Offline
    xchess64
    wrote on last edited by xchess64
    #1

    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.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • X 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.

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

      @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
      3
      • X 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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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
        0
        • JonBJ JonB

          @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 Offline
          X Offline
          xchess64
          wrote on last edited by
          #4

          @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
          2
          • jsulmJ jsulm

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

            X Offline
            X Offline
            xchess64
            wrote on last edited by
            #5

            @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.

            JonBJ 1 Reply Last reply
            0
            • X xchess64

              @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.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @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 ?

              jsulmJ 1 Reply Last reply
              1
              • JonBJ 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 ?

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

                @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
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

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

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  2

                  • Login

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