Starting an external application with arguments.



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



  • Give a try to

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

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



  • Hi,

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

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



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



  • Hi,

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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.