[Interest] Gracefully Closing a QProcess

Jason R. Kretzer jason at gocodigo.com
Fri Aug 8 20:55:41 CEST 2014


Good Day!

I saw a partial question and answer to this a bit ago on this list but I 
have a follow up scenario.

I would like to start a QProcess and connect a SLOT to its 
SIGNAL(error(QProcess::ProcessError))

In the SLOT, I would like to gracefully restart the process without 
triggering the error signal.

I have tried several ways but must be missing something.  Here is some 
sample code that I have been tinkering with:

///////////START CODE/////////////
//in an method in the "this" object
QProcess *proc = new QProcess();
QStringList arguments;
arguments << "str1" << "str2" << "str3";
proc->setArguments(arguments);
proc->setProgram("something.exe");

connect(proc, SIGNAL(error(QProcess::ProcessError)), this, 
SLOT(restartProcess(QProcess::ProcessError)));
connect(proc, SIGNAL(finished(int)), proc, SLOT(deleteLater()));
proc->start();

//in the same file
void MainWindow::restartProcess(QProcess::ProcessError err)
{
     QProcess *proc = static_cast<QProcess*>(sender());

     qDebug() << "KILLING";
     proc->close();
//******
//I have used proc->kill() and proc->terminate() here as well
//******


     qDebug() << "RESTARTING";
     proc->start();
}
/////////END CODE

So, what happens is that the proc triggers an error when I 
kill/terminate/close it.  Which triggers the function, which kills the 
process, which triggers the error  etc etc.

In the end, not sure what is the "right" way to go about this. All I 
want to do is terminate and restart a process that has triggered an error.

Thoughts?

-- 
//-----------------------//
Jason R. Kretzer
Lead Application Developer
jason at gocodigo.com
C:606.792.0079
H:606.297.2551
//-----------------------//
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140808/94e23ba1/attachment.html>


More information about the Interest mailing list