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. Starting an external application with arguments.

Starting an external application with arguments.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.4k 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.
  • musimbateM Offline
    musimbateM Offline
    musimbate
    wrote on last edited by
    #1

    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
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Give a try to

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

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mcosta
        wrote on last edited by
        #3

        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
        0
        • musimbateM Offline
          musimbateM Offline
          musimbate
          wrote on last edited by
          #4

          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
          0
          • M Offline
            M Offline
            mcosta
            wrote on last edited by
            #5

            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
            0
            • musimbateM Offline
              musimbateM Offline
              musimbate
              wrote on last edited by
              #6

              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
              0
              • D Offline
                D Offline
                dbzhang800
                wrote on last edited by
                #7

                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
                0

                • Login

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