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. Calling binaries using QProcess
Qt 6.11 is out! See what's new in the release blog

Calling binaries using QProcess

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.5k Views 1 Watching
  • 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.
  • F Offline
    F Offline
    fertinaz
    wrote on last edited by
    #1

    Hi all.

    I am trying to develop a gui using QT that runs OpenFoam (a c++ library) behind. tried to call a solver from that library using qprocess:

    @
    solverProcess = new QProcess(this);

    solverBin = "/OF_APPBIN/mysolver";

    testDir = "/fullPathTestDir";
    args << "-case" << testDir;

    solverProcess->start(solverBin, args);

    if (solverProcess->waitForStarted())
        // done@
    

    This code does not produce any errors and ends successfully however runs nothing.

    There is nothing wrong with the full path of the solver and test directory. I printed their values and could run manually on a terminal without any problems.

    Any help is appreciated.

    Note: Operating system is Ubuntu 10.10 and QT version 4.7

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vezprog
      wrote on last edited by
      #2

      First, I would try connecting the signals from QProcess readyRead(), stdOutput(), and stdError() to see if there is dependencies missing (this could cause QProcess to silently fail to start).

      Also, you'll need to define the path to the shell you are using at your program, then your first argument should be the binary location.

      For example, you use sh as your shell.
      @
      solverProcess = new QProcess(this);
      solverProcess->start("/bin/sh", QStringList() << "/OF_APPBIN/mysolver" << "-case");
      @

      If you use bash, the just replace sh with bash.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fertinaz
        wrote on last edited by
        #3

        Well thanks for the idea.

        I changed the code a little, still doesn't work though.

        This is now what I am trying:

        @
        m_SolverProcess->setStandardOutputFile("~/myTestDir/test.out", QIODevice::Append);

        m_SolverProcess->start("/bin/sh", QStringList() << "~/myTestDir/test.sh");

        if (m_SolverProcess->waitForStarted()) {
        if (m_SolverProcess->state() == QProcess::Running) {
        QMessageBox::information(NULL, "runSolver", "Done");
        }
        }
        @

        And the content of the test shell script includes the line that I actually want to run:

        @
        #!/bin/bash

        echo "Starting Run"
        echo "-------------"
        echo

        simpleFoam > log.o
        @

        When I run the code above the qt message box appears and the log files are created, as expected test.out has "starting run" and log.o is empty.

        I can run this shell script successfully on a terminal manually, so I am sure that simpleFoam is a binary that runs well. It's permissions are also correctly assigned.

        I can't seem to understand where the problem would be. Any ideas are very welcome.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          msue
          wrote on last edited by
          #4

          you can try to call the program in its directory:
          m_SolverProcess->setWorkingDirectory(prog.path());
          m_SolverProcess->start(qa("./")+prog.fileName(),args);

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vezprog
            wrote on last edited by
            #5

            As I stated before, you can check the ouput of the QProcess to standard out and standard error...

            If you want to run a direct binary, then use this to test:
            @
            QProcess *process = new QProcess(this);
            process->start("/bin/sh", QStringList() << "filename" << "argument");
            if (!process->waitForStarted(100)){ // 100mS timeout wait
            qDebug() << "STDOUT: " << process->readAllStandardOutput();
            qDebug() << "STDERR: " << process->readAllStandardError();
            }
            @

            If you want to run a script, the shell is already included, therefore use this to test:
            @
            QProcess *process = new QProcess(this);
            process->start("/path/to/script/script.sh");
            if (!process->waitForStarted(100)) // 100mS timeout wait
            qDebug() << "STDOUT: " << process->readAllStandardOutput();
            qDebug() << "STDERR: " << process->readAllStandardError();
            }
            @

            Does qDebug print anything out to the console? These can all be used event driven as well using the readyRead() signals...make sure you include <QDebug>

            1 Reply Last reply
            0
            • F Offline
              F Offline
              fertinaz
              wrote on last edited by
              #6

              I moved the installation of the third party library from my home directory to /opt and issue is solved.

              But thanks for the tip:
              @qDebug() << "STDERR: " << process->readAllStandardError();@
              that is very useful.

              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