Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Starting an external application with arguments.

    General and Desktop
    3
    7
    2140
    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.
    • musimbate
      musimbate last edited by

      Hi all ,I am trying to start an external executable from my Qt code.Following is the code I have tried.The external executable needs the setting of one specific environment variable and I hoped this would work but I am out of luck.Any ideas or hints on what might be going wrong would be appreciated.

      @

      void callTesseract()
      {

      QProcess* myProcess = new QProcess(qApp);
      QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
      env.insert("TESSDATA_PREFIX", QCoreApplication::applicationDirPath()+"/Tesseract-OCR");
      QString program="./Tesseract-OCR/tesseract.exe";
      QStringList arguments;
      arguments.append("eurotext.tif");
      arguments.append("uwamahoro");
      arguments.append("-l eng");
      myProcess->start(program, arguments);

      //
      

      }

      @

      Basicaly the code should do the same thing as calling the program from the command line like this:
      @
      tesseract eurotext.tif uwamahoro -l eng
      @

      Thanks.

      Why join the navy if you can be a pirate?-Steve Jobs

      1 Reply Last reply Reply Quote 0
      • D
        dbzhang800 last edited by

        Give a try to

        @
        arguments.append("-l");
        arguments.append("eng");
        @

        instead of
        @
        arguments.append("-l eng");
        @

        1 Reply Last reply Reply Quote 0
        • M
          mcosta last edited by

          Hi,

          you forgot to call QProcess::setProcessEnvironment() before call QProcess::start()

          @
          ...
          myProcess->setProcessEnvironment(env);
          myProcess->start(program, arguments);
          @

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          1 Reply Last reply Reply Quote 0
          • musimbate
            musimbate last edited by

            Thanks guys 1+1=2 and mcosta,your input have brought me closer to the solution but its still not working yet.Guess I still have to dig more .

            Why join the navy if you can be a pirate?-Steve Jobs

            1 Reply Last reply Reply Quote 0
            • M
              mcosta last edited by

              Hi,

              try to catch QProcess::error() signal end verify what kind of problem you have

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply Reply Quote 0
              • musimbate
                musimbate last edited by

                Thanks mcosta for the reply;
                I caught the error and it turns out that the program is not starting at all,the doc says this

                the process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program

                I think the location of the exe is right which leads me to doubting the permissions I got.Is there a way I can access and modify them from Qt?

                Also an idea crossed my mind to call cmd.exe myself and pass it the arguments.Want to hear your ideas about this.

                Thanks for the input .

                Why join the navy if you can be a pirate?-Steve Jobs

                1 Reply Last reply Reply Quote 0
                • D
                  dbzhang800 last edited by

                  Hi, from you code I can see that, the tesseract application is located in a subdirectory of your main application's directory.
                  @
                  env.insert("TESSDATA_PREFIX", QCoreApplication::applicationDirPath()+"/Tesseract-OCR");
                  QString program="./Tesseract-OCR/tesseract.exe";
                  @

                  However, relative filepath was used to stat you tesseract application.

                  Are you sure that: You Current Directory == You Application's Directory ?

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