View Full Version : Crashing on deleting QProcess

9th December 2009, 12:22
why deleting QProcess is crashing?
see my code :

m_pFindinFilesProcess = new QProcess(this);

connect(m_pFindinFilesProcess, SIGNAL(finished(int)), this, SLOT(onFindFileSearchFinished()));
connect(m_pFindinFilesProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadFindFileResult()));

m_pFindinFilesProcess->start("grep", processParam);

void MainWindow::onFindFileSearchFinished()
delete m_pFindinFilesProcess; --> Crashing here
m_pFindinFilesProcess = NULL;

:rolleyes:Must Watch:
See how we can connect digital world objects to our day to day life…. (http://www.tech2fame.info/2009/11/pranav-mistry-thrilling-potential-of.html)

9th December 2009, 13:11
You can (if not already) check that process is stopped successfully before deleting it.

if(process->state() == QProcess::NotRunning)
delete process;

9th December 2009, 17:59
Hi Rajesh,



delete m_pFindinFilesProcess;
m_pFindinFilesProcess = NULL;

There are 3 following state of process in Qt

QProcess::NotRunning 0 The process is not running.
QProcess::Starting 1 The process is starting, but the program has not yet been invoked.
QProcess::Running 2 The process is running and is ready for reading and writing.

and when QProcess exits, QProcess reenters the NotRunning state and emits finished().

but in this case buffers in QProcess are still intact and You can still read any data that the process may have written before it finished

in that case you can't delete the QProcess pointer.

before deleting QProcess pointer you need to clear the buffer by calling the

close() function.