Important: Please read the Qt Code of Conduct -

Restart QProcess

  • Hi,

    I need to launch a number of external programs from QT application and monitor their state, in case of crashing program need to be restarted. (Linux platform only)
    So I found QProcess most useful for this, but have a problem - when I get onError signal from QProcess instance, I can't re-run it with the same parameters, as process still in QProcess::Running state.

    I will be very thankful for any advice regarding QProcess re-run thick or may be any more useful way to manage processes

  • Hi,

    once you received error signal with Crashed value, you can call kill() and then re-run it

  • [quote author="mcosta" date="1364211388"]Hi,

    once you received error signal with Crashed value, you can call kill() and then re-run it

    It's not work.

    Even after kill() or terminate() QProcess state equals to QProcess::Running and trying to
    call start() will give you:
    QProcess::start: Process is already running

    I don't know, may be I'm using QProcess wrong, but it looks like a bug. Sending SIGTERM or SIGINT to external process raise only onError() signal, but state of QProcess leaves as running.
    I tried to extend QProcess with my own class and set NotRunning state manually(I know thats not correct, just for test), but QProcess also give me warning message.

  • Strange,

    when you receive error() signal, what is the error value?
    Are you sure is "Crashed"??

    Can you post you code please?

  • Looks like I found a root cause of issue. The reason is a delayed state change after kill, looks like it need to spend some main loop cycles for make QProcess object state actually changed.

    Thanks for helping, it just need a fresh head! )

  • Hi, you can use QProcess::waitForFinished() for this purpose or catch finished() signal

  • use this:

    if(normalAppProcess.state() == QProcess::NotRunning)
    normalAppProcess.start("address to your app");

Log in to reply