user3027198 user3027198 - 7 months ago 13
Bash Question

How to start a bash script in terminal from QT program?

I want the program to check if the script already started and if not - then start it (in Terminal and as root)

Thank you! ;-)

QProcess *proc = new QProcess();
proc->setWorkingDirectory("/home/user/Documents/");
proc->start("/home/user/Documents/script.sh");

delete proc;

Answer

QProcess runs the external script asyncronously, so by doing

proc->start(...);
delete proc;

You kill it as soon as it starts (or maybe even before). Try adding waitForFinished() before the delete.

proc->start(...);
proc->waitForFinished(); 
delete proc;