dasfex
dasfex

Reputation: 1260

How to wait child process with QProcess?

I am try to wait child process with this code:

auto child = new QProcess;
child->start("cmd.exe");
child->waitForFinished();

But cmd.exe doesn't open and the main program runs. What is the error?

And how I should wait correctly? waitForFinished waits 30000 msecs by default. What if I want to wait infinitely?

Upvotes: 0

Views: 325

Answers (1)

Andrea Ricchi
Andrea Ricchi

Reputation: 490

I suggest checking the return value to see if the program is started successfully using the waitForStarted (doc) and try to use the full path of CMD: "C:/windows/system32/cmd.exe".

Also, check online, the question is already been asked here.

To wait infinitely you need to call waitForFinished with -1 (doc):

child->waitForFinished(-1);

Upvotes: 3

Related Questions