QProcess doesn't emit finished signal when script completes its execution
-
Hi All,
I'm having troubles with running separate script from Qt application using QProcess.
The problem is that for some reason slot for finished signal is not invoked after the script has finished its activities.
The launched script becomes a zombie process.I'm running the script as follows:
process = new QProcess(); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onOutput())); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int,QProcess::ExitStatus))); process->start("some_script.sh");
I tried to run script itself in terminal and it didn't stuck and returned fine.
readyReadStandardOutput() is emitted when new output is generated by script and onOutput() slot is invoked.Would someone please please provide any thoughts on what might be done wrong here? I would appreciate any suggestion.
Thanks in advance.
P.S. I'm not sure if this is relevant but the application runs in QNX OS. Qt Version - 5.5.1
-
hi
On windows so cant test.
Have you tried
QProcess sh;
sh.start("sh", QStringList() << "-c" << "/path/some_script.sh");That i use for running a bat file in windows.
(well its "/c")The some_script.sh is not the process it self, a shell will also indirectly be opened.
So I wonder if that shell remains open. -
Hi,
You should also check the error output.
Note that you try to start
"some_script.sh"
which is a relative path so you are likely not even starting it unless you copied it in the same folder where the application got built (Qt Creator shadow build).One way to validate that is to put the fullpath to the script in the
QProcess::start
call. -
Thanks for your suggestion,
The the path to script is absolute. I'm sure.
I have tried to run the following script and faced same problem:#!/bin/sh sleep 1 echo "TEST MESSAGE 1" sleep 2 echo "TEST MESSAGE 2" sleep 1 echo "TEST MESSAGE 3" sleep 1 echo "TEST MESSAGE 4" sleep 1 exit 0
Finished signal is not coming
-
That:
process->start("some_script.sh");
is not an absolute path.Did you check that you get anything ? What about using waitForStarted ?
-
-
Hi @diredko,
I merged your code into an existing project for a quick test (on Ubuntu 15.10), and it worked as expected:
MainWizard::MainWizard(QWidget *parent, Qt::WindowFlags flags): QWizard(parent,flags) { QProcess * const process = new QProcess(); connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(onOutput())); connect(process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(onFinished(int,QProcess::ExitStatus))); process->start("sh", QStringList() << "-c" << "/home/paul/some_script.sh"); } void MainWizard::onOutput() { qDebug() << __func__ << qobject_cast<QProcess *>(sender())->readAllStandardOutput(); } void MainWizard::onFinished(int code, QProcess::ExitStatus status) { qDebug() << __func__ << code << status; }
Output:
onOutput "TEST MESSAGE 1 " onOutput "TEST MESSAGE 2 " onOutput "TEST MESSAGE 3 " onOutput "TEST MESSAGE 4 " onFinished 0 0
Can you provide a complete, cut-down example that exhibits the problem? Otherwise, at least the show us the main function, the class that owns the QProcess pointer and slots, and the code that instantiates an instance of that class.
Then I'll test that out, and see if I can reproduce the issue :)
Cheers.
-
Hi,
Thanks for your response. The whole body of code is proprietary so I'm not sure I can share it in a public forum.
However I can make a note that it used to work fine a month ago and after that no changes occurred to this code and no qt libraries were replaced, so the issue is like to be caused by hardware malfunction.Thanks again ))