[Interest] Finished signal from QProcess!
Lata Agrawal
lata.agrawal at enrouteinc.com
Wed Feb 29 07:46:51 CET 2012
On 29 February 2012 10:36, Mandeep Sandhu <mandeepsandhu.chd at gmail.com>wrote:
> On Wed, Feb 29, 2012 at 10:09 AM, Lata Agrawal
> <lata.agrawal at enrouteinc.com> wrote:
> > Hi,
> >
> > I am running console application C1 in QProcess. I am starting this
> console
> > application C1 from another console application C2. Problem is:
> > I am only getting finished signal from C1 when I use waitforfinshed()
> else I
> > am not getting finished signal from C1. Here is the code:
>
> Does your console app C1 quit after completing its work? Or is the
> event loop still running in C1?...have your called
> QApplication::quit/exit in C1 after it's done with it work? If not
> then C1 will continue to run untill explicitly exited (or killed from
> outside).
>
yes, on using ps command in terminal, I can see the process C1 but in
defunct state. I used return a.exec() in C1 along with a timer
QTimer::singleshot(0, &a, SLOT(quit()).
>
> >
> > QString strProgram;
> > strProgram = <Path to C1>;
> >
> > updateProc->setProcessChannelMode(QProcess::ForwardedChannels);
> > connect(updateProc,
> > SIGNAL(finished(int,QProcess::ExitStatus)),
> > SLOT(procStarted(int,QProcess::ExitStatus)), Qt::DirectConnection);
>
> 'procStarted' seems to be strange name for a slot handling the
> 'finished' singla!! :)
>
I know. actually i created this slot for started() signal, but then
eventually connected it for finished signal.
> >
> > updateProc->setStandardOutputProcess(this->thread()->parent());
> > updateProc->start(strProgram, arguments);
>
> Why is this needed? Is C2 processing o/p of C1...or do you simply want
> to print stdout of C1 in C2's stdout (if so, then you've already done
> that by setting the channel mode above)?
>
Sorry, this is supposed to be commented.
>
> >
> > //Download is over, indicate through bool variable that
> next
> > downlaod can be started
> > if(updateProc->waitForFinished(-1))
> > {
> > qDebug("Update process finished!\n");
> > }
> > else
> > {
> > qDebug("Update process not yet finished!\n");
> > }
> >
> > void FloDownloadManager::procStarted(int retVal ,QProcess::ExitStatus
> > exitStat)
> > {
> > qDebug("Update process finished automatically!\n");
> > if(currentExecutingPriority == AdsUpdate)
> > {
> > emit adUpdateDone();
> > }
> > blnStartNextUpdate = true;
> >
> > updateProc->deleteLater();
> > }
> >
> >
> > If I comment the waitforfinished() code, I don't get the finished signal.
> > But if I include the waitforfinished() signal, I don't get the finished
> > signal. Code for C1 is as follows:
> >
> > #include <QtCore/QCoreApplication>
> > #include "updater.h"
> >
> > int main(int argc, char *argv[])
> > {
> > QCoreApplication a(argc, argv);
> >
> > qDebug("Inside Updater\n");
> >
> > QTimer::singleShot(5000, &a, SLOT(quit()));
> > qDebug("returning from Updater process!@@@@@@@@\n");
> >
> > return 0;
> > }
>
> You have not started the apps event loop!!!...what do you expect it
> do? This program will exit out immediately! You need to do a.exec()
> for the timer signal to be processed.
>
This I tried but still no finished signal.
>
> >
> > I read on other forums that if main process does not wait for child
> process
> > to finish like using waitforfinished, then finished signal will not be
> sent
> > to main process, rather child process after finishing will become
> defunct or
> > zombie. In my code above, if I use waitforfinished, then main process
> does
> > receive finished signal.
>
> AFAIK, in linux, if the parent process dies before a child process
> finishes, it is re-parented to init (process with pid 1). This is
> called an 'orphaned' process. Not to be confused with a zombie/defunct
> in which a process has exited, but it's entry has not been removed
> from process table.
>
You are right. But when I use ps, I se my C1 listed as C1 defunct. If I am
not wrong, this means a zombied process, which has finished but whose
parent process is still alive. Right?
>
> More:
> http://en.wikipedia.org/wiki/Orphan_process
> http://en.wikipedia.org/wiki/Zombie_process
>
> >
> > Is there any way by which main process can receive finished signal
> without
> > waiting for child process to finish?
>
> Yes, by connecting to the child QProcess's 'finished' signal. Thats
> what the signal is there for! :) It tells the parent when a process
> has exited and with what exit code.
>
One more thing, in C2 (the main process, I have called a class which starts
an infinite loop and a.exec is called after that which essentially means
a.exec() is never called. Is this the reason why I am not getting finished
signal? Code is shown below:
int main(int argc, char *argv[])
{
Class1 downloadMngr;
downloadMngr.startDownload(); //This starts an infinite loop which
waits for items to be added to queue
return a.exec(); //So this is probably never called.
}
How can I start eventloop in main() while having the functionality in
Class1.
Regards,
Lata
>
> HTH,
> -mandeep
>
> > Regards,
> > Lata
> >
> >
> > --
> >
> >
> > Lata Agrawal
> > Senior Developer
> > 9699750643
> > En Route Media Pvt. Ltd.
> >
> >
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
> >
>
--
*
*Lata Agrawal
Senior Developer
9699750643
En Route Media Pvt. Ltd.
* *
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120229/039ab19c/attachment.html>
More information about the Interest
mailing list