Andrew Tomazos
Andrew Tomazos

Reputation: 68658

QProcess signals emitted after start called?

After start() is called on a QProcess object, what are the possible sequences of signal emissions that can follow to started, errorOccurred and finished ?

(Is the started signal always emitted? Is the finished signal always emitted? Are at least one of the three signals always emitted? If errorOccurred is emitted can a started or finished signal be emitted after it?)

Upvotes: 1

Views: 592

Answers (1)

Farshid616
Farshid616

Reputation: 1484

When you call start() for a QProcess object, as soon as your process be started the started signal will be emit. If there occur any error in your process errorOccurred will emit and after finished of your process the finished signal will be called. But Finished signal always emit after some seconds so if you need to run a chain of commands you can use faster way instead of using finished signal like below:

QProcess *system_command = new QProcess();
system_command->start("/bin/bash");
system_command->waitForFinished(500);
system_command->write("ls -a\n");

Update:

No, the sequence isn't always the same. If your process started successfully and doesn't return an error it will emit started signal. Now if your process run a program that not finished or it is waiting for some command, finished signal will not emitted until that process finished successfully (It may never emit finished signal).

If your process encounter and error, errorOccured will emitted but started and finished signal will not emit.

Example:

If you run a bash with QProcess it will only emit started signal and finished signal never will emitted. Because it's waiting for other commands.

system_command->start("/bin/bash");

But if you run a bash with all of the commands that you want to run instantly, it will run and emit finished signal (in case of no error occurred).

readtimedatectl->start("/bin/sh", QStringList() << "-c" << "timedatectl");

Upvotes: 1

Related Questions