Calling a binary file (Openfoam solver) through QT
-
wrote on 15 Jun 2018, 13:16 last edited by VRonin
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! -
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!wrote on 15 Jun 2018, 13:24 last edited by@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. -
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!wrote on 15 Jun 2018, 13:47 last edited by@JVRS welcome to the forum. Some things here.
- Whenener posting code snippets, please try to sorround it with proper markup :-)
-
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);
-
wrote on 15 Jun 2018, 13:57 last edited by
@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) -
@JVRS welcome to the forum. Some things here.
- Whenener posting code snippets, please try to sorround it with proper markup :-)
-
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);
wrote on 15 Jun 2018, 14:01 last edited by@Pablo-J.-Rogina
In this case the user is choosing to use the voidQProcess::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. -
@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)wrote on 15 Jun 2018, 14:11 last edited byQProcess::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. -
@JVRS welcome to the forum. Some things here.
- Whenener posting code snippets, please try to sorround it with proper markup :-)
-
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);
wrote on 15 Jun 2018, 14:11 last edited by@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);
-
wrote on 15 Jun 2018, 14:16 last edited by
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
-
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
wrote on 15 Jun 2018, 14:29 last edited by@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 :) -
wrote on 15 Jun 2018, 14:51 last edited by
@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.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-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.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.wrote on 15 Jun 2018, 14:58 last edited by@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.
-
@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.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.wrote on 15 Jun 2018, 15:11 last edited by@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
-
@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
wrote on 15 Jun 2018, 15:41 last edited by@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.-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?wrote on 15 Jun 2018, 15:45 last edited by@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
-
@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
wrote on 15 Jun 2018, 16:18 last edited by@Pablo-J.-Rogina Thank you very much for your help !! Regards
1/15