QProcess and shell: destroyed while the process is still running

I want to run a shell script with Qt.

QProcess process;
process.start(commandLine, QStringList() << confFile);
process.waitForFinished();

if(process.exitCode()!=0)
{
    qDebug () << " Error " << process.exitCode() << process.readAllStrandardError();
}
else
{
    qDebug () << " Ok " << process.readAllStrandardOutput() << process.readAllStrandardError();
}

      

Result:

Ok: Result .... "" QProcess: Destroyed while process is still running.

This message does not appear every time.

What is the problem?

+3


source to share


2 answers


process.waitForFinished();

strikes by default 30 seconds. Use instead process.waitForFinished(-1);

. This will allow you to wait for how long it takes for the process to complete, without any timeout.



+8


source


Note that you are creating a QProcess in the local scope. This means that the object will be removed when leaving the area. In the destructor, the QProcess ends. "Destroyed" message while "process is still running" when the process exits in the destructor.

To solve this problem, you must call the QProcess destructor when the process has already exited.



If your example is QProcess :: waitForFinished (-1) this will happen, but it will block your application.

0


source







All Articles