Calling executable using QProcess
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,
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?