PDA

View Full Version : doubt in Qprocess.waitforfinished



iswaryasenthilkumar
24th September 2015, 06:15
am doing HLS conversion using Qprocess,hls conversion takes 20 minutes,if it takes above 20 minutes i should through error,and return back to mainscreen.here my problem is when hls conversion fails below20 minutes,my Qprocess waits for 20 minutes after reaches 20 minutes it stops the hls conversion it not showing error


bool status;
QProcess process;
QStringList arguments;
QString program ="/bin/sh";
arguments << SCRIPTFILEPATH;
process.start(program, arguments);
status=process.waitForFinished(waitminutes); //waitminute contains =1200000
qDebug()<<status<<"status for Qprocess";
if(!status)
{
errorstatus("Movie Conversion has Errors. Check the DVD Media ");
return FAIL;
}
return SUCCESS;

i know am doing mistakes here please kindly help me to rectify my problems
Thanks in advance:)

yeye_olive
24th September 2015, 08:59
Your code lets the process run for at most 20 minutes. If the process terminates or crashes within 20 minutes, your code returns SUCCESS as soon as that happens. Otherwise it returns FAIL when the 20 minutes have elapsed.

What do you mean by "hls conversion fails below20 minutes"? Do you mean that the process terminates before the 20 minutes have elapsed, but has not successfully performed the task you expected?

Please note that QProcess does not know anything about the task performed by the process. It cannot distinguish between a process that terminates, having successfully performed its expected task, and a process that terminates, having failed to do so. All it knows it whether the process has terminated or crashed and, if it has terminated, its exit code.

jefftee
24th September 2015, 09:09
QProcess::waitForFinished should return false when the QProcess ends with an error *or* the number of milliseconds is reached. It should return true only when the process is finished before the number of milliseconds are reached *and* the QProcess ended normal (return code 0).

What is the return value from QProcess::waitForFinished and what is the QProcess::exitCode and QProcess::exitStatus? I don't believe you can do what you want by inspecting only the return value from QProcess::waitForFinished.

IMHO, if you're going to use the QProcess::waitForFinished method, you should probably make sure your process has started by using QProcess::waitForStarted as well.

yeye_olive
24th September 2015, 10:46
QProcess::waitForFinished should return false when the QProcess ends with an error *or* the number of milliseconds is reached. It should return true only when the process is finished before the number of milliseconds are reached *and* the QProcess ended normal (return code 0).
Really? The documentation is highly ambiguous:

Returns true if the process finished; otherwise returns false (if the operation timed out, if an error occurred, or if this QProcess is already finished).
I do not know what to make of this "an error occurred" condition. You seem to interpret an exit with code != 0 as such an error. From a quick look at the implementation, I believe, by contrast, that these errors are limited to internal errors (e.g. the underlying call to select() or the equivalent primitive fails).

EDIT:
I tested it on Linux and can confirm that waitForFinished() returns true when the process exits with a nonzero code.

jefftee
24th September 2015, 16:21
yeye_olive, you may be correct. I've never used the waitFor* methods as I stated in my post. Agree that the doc isn't as clear as it could be, but regardless of which view is correct, the OP needs to better describe what's occurring because I surely could not tell. :)