tags:

views:

906

answers:

1

I'm on the path to write a QCoreApplication supposed to create an external process via Qprocess.

I've just noticed that even if the waitForStarted() is called and the process state is Running before the event handler is executing, the external process does not start until the exec() method is invoked on the QCoreApplication.

That said, is it possible to postpone the execution of a routine to the event handling start (in which to instantiate a QProcess), or the only viable way is to create a one shot QTimer?

+1  A: 

After a short investigation it comes out the method QCoreApplication::processEvents() that processes all pending events for the calling thread. In the following code

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QProcess abc(....);
    abc.start(...);

    app.processEvents();

    //////////////////////////////////////////////////////
    // is the process really running ? //
    //////////////////////////////////////////////////////

    return  app.exec();
}

such method is required for the section is-the-process-really-running to let it find the abc process up and running. Otherwise abc will be started when the event loop processes the start event.

Nicola Bonelli