Results 1 to 3 of 3

Thread: Crashing on deleting QProcess

  1. #1
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Crashing on deleting QProcess

    why deleting QProcess is crashing?
    see my code :
    Qt Code:
    1. {
    2. ...
    3. m_pFindinFilesProcess = new QProcess(this);
    4.  
    5. connect(m_pFindinFilesProcess, SIGNAL(finished(int)), this, SLOT(onFindFileSearchFinished()));
    6. connect(m_pFindinFilesProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadFindFileResult()));
    7.  
    8. m_pFindinFilesProcess->start("grep", processParam);
    9. }
    10.  
    11. void MainWindow::onFindFileSearchFinished()
    12. {
    13. if(m_pFindinFilesProcess)
    14. {
    15. delete m_pFindinFilesProcess; --> Crashing here
    16. m_pFindinFilesProcess = NULL;
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 



    Must Watch:
    See how we can connect digital world objects to our day to day life….

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Crashing on deleting QProcess

    You can (if not already) check that process is stopped successfully before deleting it.
    Qt Code:
    1. if(process->state() == QProcess::NotRunning)
    2. delete process;
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Dec 2009
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Crashing on deleting QProcess

    Hi Rajesh,

    Solution:

    m_pFindinFilesProcess->close();

    if(m_pFindinFilesProcess)
    {
    delete m_pFindinFilesProcess;
    m_pFindinFilesProcess = NULL;
    }

    Why:
    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.

Similar Threads

  1. [Article] How to QProcess in QThread
    By Raccoon29 in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2009, 08:22
  2. Detect First QProcess finished in a group and kill other
    By Davidaino in forum Qt Programming
    Replies: 3
    Last Post: 11th July 2008, 12:53
  3. Deleting QProcess
    By user_mail07 in forum Qt Programming
    Replies: 7
    Last Post: 29th January 2008, 18:55
  4. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  5. Replies: 4
    Last Post: 13th February 2006, 11:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.