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 a binary file (Openfoam solver) through QT
Forum Updated to NodeBB v4.3 + New Features

Calling a binary file (Openfoam solver) through QT

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 2.8k 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.
  • J Offline
    J Offline
    JVRS
    wrote on last edited by VRonin
    #1

    Hello,
    First of all i must say i'm newbie to qt and openfoam. I'm developing an application that runs OpenFoam (a c++ library) behind. I'm trying to call a solver from that library by pressing a pushButton and using qprocess as follows:

    //...............................................//
    void MainWindow::on_pB_run_clicked()
    {
        QProcess myProcess;
        myProcess.start("icoFoam -case /home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123");
        myProcess.waitForFinished();
    }
    //.........................................................//
    

    The binary is icoFoam and the case argument tells the folder where to run it.
    If i type the entire command "icoFoam -case /home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123" in the command line it runs perfectly.
    If i run on qt through qprocess it doens't do anything.
    I would appreciate if anyone could help me with this problem.
    Regards!

    JonBJ Pablo J. RoginaP 2 Replies Last reply
    0
    • J JVRS

      Hello,
      First of all i must say i'm newbie to qt and openfoam. I'm developing an application that runs OpenFoam (a c++ library) behind. I'm trying to call a solver from that library by pressing a pushButton and using qprocess as follows:

      //...............................................//
      void MainWindow::on_pB_run_clicked()
      {
          QProcess myProcess;
          myProcess.start("icoFoam -case /home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123");
          myProcess.waitForFinished();
      }
      //.........................................................//
      

      The binary is icoFoam and the case argument tells the folder where to run it.
      If i type the entire command "icoFoam -case /home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123" in the command line it runs perfectly.
      If i run on qt through qprocess it doens't do anything.
      I would appreciate if anyone could help me with this problem.
      Regards!

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

      @JVRS
      There are many possibilities as to why it might not run correctly from a Qt GUI app while it does OK from some command line.

      Start by at least hooking up the errorOccurred & finished signals to see if they indicate anything.

      1 Reply Last reply
      0
      • J JVRS

        Hello,
        First of all i must say i'm newbie to qt and openfoam. I'm developing an application that runs OpenFoam (a c++ library) behind. I'm trying to call a solver from that library by pressing a pushButton and using qprocess as follows:

        //...............................................//
        void MainWindow::on_pB_run_clicked()
        {
            QProcess myProcess;
            myProcess.start("icoFoam -case /home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123");
            myProcess.waitForFinished();
        }
        //.........................................................//
        

        The binary is icoFoam and the case argument tells the folder where to run it.
        If i type the entire command "icoFoam -case /home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123" in the command line it runs perfectly.
        If i run on qt through qprocess it doens't do anything.
        I would appreciate if anyone could help me with this problem.
        Regards!

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @JVRS welcome to the forum. Some things here.

        1. Whenener posting code snippets, please try to sorround it with proper markup :-)
        2. i'm newbie to qt

        More than ever, documentation is your friend. Try to spend some time getting familiar with the capabilities of the Qt classes you'll end up using. From QProcess documentation, you'll find this code snippet showing exactly what I guess you need, you'll figure out what is the proper code for your use case:

            QString program = "./path/to/Qt/examples/widgets/analogclock";
            QStringList arguments;
            arguments << "-style" << "fusion";
        
            QProcess *myProcess = new QProcess(this);
            myProcess->start(program, arguments);
        

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        JonBJ J 2 Replies Last reply
        3
        • J Offline
          J Offline
          JVRS
          wrote on last edited by
          #4

          @JonB said in Calling a binary file (Openfoam solver) through QT:

          finished

          Thank you for your fast response. I placed an output qDebug for the process state, error, exit code and exit status and got this:

          QProcess::ProcessState(NotRunning)
          QProcess::ProcessError(FailedToStart)
          1011073872
          QProcess::ExitStatus(21952)

          JonBJ 1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @JVRS welcome to the forum. Some things here.

            1. Whenener posting code snippets, please try to sorround it with proper markup :-)
            2. i'm newbie to qt

            More than ever, documentation is your friend. Try to spend some time getting familiar with the capabilities of the Qt classes you'll end up using. From QProcess documentation, you'll find this code snippet showing exactly what I guess you need, you'll figure out what is the proper code for your use case:

                QString program = "./path/to/Qt/examples/widgets/analogclock";
                QStringList arguments;
                arguments << "-style" << "fusion";
            
                QProcess *myProcess = new QProcess(this);
                myProcess->start(program, arguments);
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @Pablo-J.-Rogina
            In this case the user is choosing to use the void QProcess::start(const QString &command, QIODevice::OpenMode mode = ReadWrite) overload, i.e. where the command is passed as a single string instead of separated arguments. I looked carefully at his arguments and cannot see a problem in terms of quoting, so I assume he would encounter the same error, whatever the cause is.

            1 Reply Last reply
            1
            • J JVRS

              @JonB said in Calling a binary file (Openfoam solver) through QT:

              finished

              Thank you for your fast response. I placed an output qDebug for the process state, error, exit code and exit status and got this:

              QProcess::ProcessState(NotRunning)
              QProcess::ProcessError(FailedToStart)
              1011073872
              QProcess::ExitStatus(21952)

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

              @JVRS

              QProcess::FailedToStart 0 The process failed to start. Either the invoked program is missing, or you may have insufficient permissions to invoke the program.

              The usual cause is that icoFoam is not on the PATH used from the GUI app, but is from the command-line?

              Otherwise (apart from trying @Pablo-J-Rogina 's suggestion if it's a quoting problem, which I don't think it is): check http://doc.qt.io/qt-5/qprocess.html#readAllStandardError . You may be getting some info on stderr to tell you what the issue is.

              1 Reply Last reply
              0
              • Pablo J. RoginaP Pablo J. Rogina

                @JVRS welcome to the forum. Some things here.

                1. Whenener posting code snippets, please try to sorround it with proper markup :-)
                2. i'm newbie to qt

                More than ever, documentation is your friend. Try to spend some time getting familiar with the capabilities of the Qt classes you'll end up using. From QProcess documentation, you'll find this code snippet showing exactly what I guess you need, you'll figure out what is the proper code for your use case:

                    QString program = "./path/to/Qt/examples/widgets/analogclock";
                    QStringList arguments;
                    arguments << "-style" << "fusion";
                
                    QProcess *myProcess = new QProcess(this);
                    myProcess->start(program, arguments);
                
                J Offline
                J Offline
                JVRS
                wrote on last edited by
                #7

                @Pablo-J.-Rogina thanks for your response and advice :)
                I've already provided full path to the binary i want to run and separated the arguments like this:

                QString program = "/opt/openfoam5/platforms/linux64GccDPInt32Opt/bin/icoFoam";
                        QStringList arguments;
                        arguments << "-case" << "/home/jvrs/ProjetosQT/Aplicação_Beta/SimulationData/NewCases/123";
                
                        QProcess *myProcess = new QProcess(this);
                        myProcess->start(program, arguments);
                
                1 Reply Last reply
                0
                • VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  You are passing non-ascii input (çã) without specifying any encoding/decoding. try renaming your folder to ascii only. if it works then you just have to handle unicode more carefully when creating strings

                  "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                  ~Napoleon Bonaparte

                  On a crusade to banish setIndexWidget() from the holy land of Qt

                  JonBJ 1 Reply Last reply
                  4
                  • VRoninV VRonin

                    You are passing non-ascii input (çã) without specifying any encoding/decoding. try renaming your folder to ascii only. if it works then you just have to handle unicode more carefully when creating strings

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

                    @VRonin
                    Now I wondered about just that. But user states command works from "command-line". Also, those chars look UTF-8, and Linux filing system is supposed to be UTF-8.

                    If he does not want to "rename the folder" (why should he?), what does he have to do for passing to QProcess that he does not have to do in a Linux shell. I'd like to understand this, if you'd be kind enough, as otherwise I consider myself a bit of Linux-process-wizard :)

                    1 Reply Last reply
                    0
                    • J Offline
                      J Offline
                      JVRS
                      wrote on last edited by
                      #10

                      @Pablo-J-Rogina I've tried what you suggested and it didn't work.
                      @VRonin i've already changed the folder name and it is the same.
                      @JonB yes if I type that command on command line it runs.

                      0_1529074012615_Captura de ecrã de 2018-06-15 15-40-44.png

                      I just want to simply do the same but on qt with the press of a button.
                      Thank you all , as a new user i need to wait a certain amount of time in order to post again. sorry for the delay.

                      JonBJ Pablo J. RoginaP 2 Replies Last reply
                      0
                      • J JVRS

                        @Pablo-J-Rogina I've tried what you suggested and it didn't work.
                        @VRonin i've already changed the folder name and it is the same.
                        @JonB yes if I type that command on command line it runs.

                        0_1529074012615_Captura de ecrã de 2018-06-15 15-40-44.png

                        I just want to simply do the same but on qt with the press of a button.
                        Thank you all , as a new user i need to wait a certain amount of time in order to post again. sorry for the delay.

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

                        @JVRS

                        @JonB yes if I type that command on command line it runs.

                        Yes, I understand that.

                        I really think you should act on my previous:

                        check http://doc.qt.io/qt-5/qprocess.html#readAllStandardError . You may be getting some info on stderr to tell you what the issue is.

                        1 Reply Last reply
                        0
                        • J JVRS

                          @Pablo-J-Rogina I've tried what you suggested and it didn't work.
                          @VRonin i've already changed the folder name and it is the same.
                          @JonB yes if I type that command on command line it runs.

                          0_1529074012615_Captura de ecrã de 2018-06-15 15-40-44.png

                          I just want to simply do the same but on qt with the press of a button.
                          Thank you all , as a new user i need to wait a certain amount of time in order to post again. sorry for the delay.

                          Pablo J. RoginaP Offline
                          Pablo J. RoginaP Offline
                          Pablo J. Rogina
                          wrote on last edited by
                          #12

                          @JVRS How are you running your Qt application? If it's from Qt Creator, please trying launching Qt Creator from command line, not from menu entry so to have exactly same PATH value

                          Upvote the answer(s) that helped you solve the issue
                          Use "Topic Tools" button to mark your post as Solved
                          Add screenshots via postimage.org
                          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                          J 1 Reply Last reply
                          3
                          • Pablo J. RoginaP Pablo J. Rogina

                            @JVRS How are you running your Qt application? If it's from Qt Creator, please trying launching Qt Creator from command line, not from menu entry so to have exactly same PATH value

                            J Offline
                            J Offline
                            JVRS
                            wrote on last edited by
                            #13

                            @Pablo-J.-Rogina Bingo! it runs!! thank you so much !! :) why is that? Do i always need to launch the application from command line?

                            Apart from this i also tried a different solver, i.e, instead of icoFoam, i used another solver. Similarly is works perfectly on command line, but when i launch from qt it doens't work, even if qt is launched from commandline.
                            Is this something similarly to my initial problem?

                            Pablo J. RoginaP 1 Reply Last reply
                            0
                            • J JVRS

                              @Pablo-J.-Rogina Bingo! it runs!! thank you so much !! :) why is that? Do i always need to launch the application from command line?

                              Apart from this i also tried a different solver, i.e, instead of icoFoam, i used another solver. Similarly is works perfectly on command line, but when i launch from qt it doens't work, even if qt is launched from commandline.
                              Is this something similarly to my initial problem?

                              Pablo J. RoginaP Offline
                              Pablo J. RoginaP Offline
                              Pablo J. Rogina
                              wrote on last edited by
                              #14

                              @JVRS said in Calling a binary file (Openfoam solver) through QT:

                              why is that? Do i always need to launch the application from command line?

                              Weather your Qt app is launched from command line or from Qt Creator what you need is that the PATH and eventually LD_LIBRARY_PATH, are set properly so the process you're launching from Qt app is found and all the libraries it requires are available.

                              If you issue if solved now, please don't forget to mark it as such. Thanks

                              Upvote the answer(s) that helped you solve the issue
                              Use "Topic Tools" button to mark your post as Solved
                              Add screenshots via postimage.org
                              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                              J 1 Reply Last reply
                              3
                              • Pablo J. RoginaP Pablo J. Rogina

                                @JVRS said in Calling a binary file (Openfoam solver) through QT:

                                why is that? Do i always need to launch the application from command line?

                                Weather your Qt app is launched from command line or from Qt Creator what you need is that the PATH and eventually LD_LIBRARY_PATH, are set properly so the process you're launching from Qt app is found and all the libraries it requires are available.

                                If you issue if solved now, please don't forget to mark it as such. Thanks

                                J Offline
                                J Offline
                                JVRS
                                wrote on last edited by
                                #15

                                @Pablo-J.-Rogina Thank you very much for your help !! Regards

                                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