Planned maintenance has been done but it did not solve the problem. So work will continue on this and a new time for trying updates will be announced asap.
Calling executable using QProcess
Chandras002 last edited by
Dear Qt community!
Cheers! I am trying to call a Linux executable from Qt GUI. The simple GUI button has "Open File Name" button. Once button clicked - the executable launch from Terminal. i.e open the Gnome Terminal first , execute the file in given path. i.e equivalent to ./testfile I am using Ubuntu.
QProcess *process=new QProcess(new QProcess()); // QProcess *process=new QProcess(this); QString program = "/home/Desktop/Testfile"; process->start(program, QStringList() << " "); // process->start("cd /home/yogin/&& Testfile"); //checking the process start qDebug()<<"Process started"; /*Success message*/ QMessageBox::information(this,"Alert"," Calling Executable success!");
Now, the program runs without error but the executable not launching. Please note,
- enabled the "Run in Terminal option on Qt Run setting.
- added the export PATH="$PATH:." ,so the file will run without ./ on Terminal.
Attached screen shots (Reverse order) Not sure why getting "Child process exited with status 0"
Any ideas/tips highly useful. Thanks a lot !
With kind regards,
JonB last edited by JonB
QString program = "/home/Desktop/Testfile"; process->start(program, QStringList() << " ");
Why do you pass a single argument of a space character to your program?
/home/Desktop/Testfilean executable file? If it isn't, nothing is going to run....
... And you do not check for errors (you just assume it is running), wait for it to complete, or anything.
The only reason you're seeing the Terminal window at all is because of your
1.enabled the "Run in Terminal option on Qt Run setting.
Outside of Qt Creator that would not be shown.
My guess is that you're seeing nothing because you're not actually succeeding in executing anything, and doubtless there will be an error there (which you're not seeing) to that effect.
Besides @JonB s good points im wondering
what testfile is ?
Did you compiled the program yourself or
where did u get it?
Chandras002 last edited by
Sorry for late reply.
The testfile is executable which involves calling some processor related info using Intel API's . even with out using Qt, I am believe this executable not have an option "Open with Command Shell" on Ubuntu. So, think it is not Qt issue. Any tips, how to make the Linux executable(testfile) with Open with application command shell by default. I trying to achieve this before use Qt to run the testfile .
Any tips, how to make the Linux executable
chmod u+x /home/Desktop/Testfile
Also, did you remove that empty parameter
QString program = "/home/Desktop/Testfile"; process->start(program, QStringList() << " "); // Why this " "?!
Connect a slot to http://doc.qt.io/qt-5/qprocess.html#errorOccurred and print the error in the slot.
QProcess *process=new QProcess(new QProcess());
looks strange. why not
QProcess *process=new QProcess(this);or just
QProcess *process=new QProcess;?