Results 1 to 12 of 12

Thread: My program crashes if QProcess is restarted directly when it has finished

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: My program crashes if QProcess is restarted directly when it has finished

    Apparently notRunning != finished(). On Linux I get the following warning on the command line:
    QSocketNotifier: Multiple socket notifiers for same socket 15 and type Read
    Try the following code:
    Qt Code:
    1. #include <QCoreApplication>
    2. #include <QProcess>
    3. #include <QDebug>
    4. #include <QTimer>
    5.  
    6. class process_handler : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. process_handler() {
    11. connect(&p, SIGNAL(stateChanged(QProcess::ProcessState)), this, SLOT(process_state_changed(QProcess::ProcessState)));
    12. connect(&p, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(process_finished(int, QProcess::ExitStatus)));
    13. start_process();
    14. }
    15. public slots:
    16. void process_state_changed(QProcess::ProcessState state) {
    17. if (state == QProcess::Starting)
    18. qDebug() << "Process is starting up...";
    19. if (state == QProcess::Running)
    20. qDebug() << "Process is now running." ;
    21. if (state == QProcess::NotRunning){
    22. qDebug() << "Process is finished running.";
    23. start_process();
    24. //QTimer::singleShot(0, this, SLOT(start_process()));
    25. }
    26. }
    27. void process_finished(int , QProcess::ExitStatus ){
    28. qDebug() << "received finished signal";
    29. }
    30. void start_process() {
    31. p.start("ping 1.1.1.1 -c 1 -W 3"); // from your previous thread
    32. }
    33. private:
    34. };
    35.  
    36. int main(int argc, char *argv[]) {
    37. QCoreApplication app(argc, argv);
    38. process_handler ph;
    39. app.exec();
    40. }
    41. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 
    The output on my box is:
    Process is starting up...
    Process is now running.
    Process is finished running.
    QSocketNotifier: Multiple socket notifiers for same socket 15 and type Read
    Process is starting up...
    received finished signal
    I haven't looked at the source code but what appears to happen is the new process assigns a QSocketNotifier to the same
    socket as the old process and the old process deletes the socket. My app just idles in the event loop after the output
    above. Maybe Windows segfaults?

  2. The following user says thank you to norobro for this useful post:

    Yes (18th September 2012)

Similar Threads

  1. Replies: 2
    Last Post: 13th July 2011, 02:52
  2. Replies: 0
    Last Post: 26th August 2010, 10:44
  3. QProcess::finished problems again
    By mdicosimo in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 21:43
  4. QProcess::finished()
    By T1c4L in forum Qt Programming
    Replies: 11
    Last Post: 9th July 2008, 20:06
  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
  •  
Qt is a trademark of The Qt Company.