Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QProcess and shell : Destroyed while process is still running

I want to launch 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();
}

The result is :

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

This message does not appear every time.

What is the problem?

like image 584
user2007861 Avatar asked Jan 24 '13 14:01

user2007861


2 Answers

process.waitForFinished(); is hitting the default 30 seconds timeout. Use process.waitForFinished(-1); instead. This will make sure you wait for however long it takes for the process to finish, without any timeout.

like image 115
sashoalm Avatar answered Nov 02 '22 06:11

sashoalm


Note you create QProcess into the local scope. This means that the object will be deleted when you exit the scope. In the destructor QProcess process terminates. The message "Destroyed" while "the process is still running" when the process terminates in the destructor.

For solving this problem, you should call QProcess destructor when process is already terminated.

If will be QProcess::waitForFinished(-1) into your example, it will occur, but this will block you application.

like image 3
synacker Avatar answered Nov 02 '22 05:11

synacker