From ed0c0070f9b05c647019270dfc42073d071c830a Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Mon, 8 Dec 2014 15:29:19 +0100 Subject: Introduce qt_subtract_from_timeout to reduce code duplication. The same qt_timeout_value function was copied 5 times in qtbase's code, so provide a common implementation in QIoDevice that can be used by everyone. This commit also corrects the remaining time calculation in QProcess::waitForBytesWritten and QProcess::waitForFinished by using this new function. For QProcess::waitForFinished, if the process started within almost exactly the timeout time passed to waitForFinished, msecs - stopWatch.elapsed() would be -1, which is a special value. Change-Id: I7b76ee6bae695eafdd02e3db03e2ff1e23a7f40c Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qprocess.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/corelib/io/qprocess.cpp') diff --git a/src/corelib/io/qprocess.cpp b/src/corelib/io/qprocess.cpp index 94912ad616..baba9a0f9e 100644 --- a/src/corelib/io/qprocess.cpp +++ b/src/corelib/io/qprocess.cpp @@ -1793,8 +1793,7 @@ bool QProcess::waitForBytesWritten(int msecs) bool started = waitForStarted(msecs); if (!started) return false; - if (msecs != -1) - msecs -= stopWatch.elapsed(); + msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed()); } return d->waitForBytesWritten(msecs); @@ -1830,8 +1829,7 @@ bool QProcess::waitForFinished(int msecs) bool started = waitForStarted(msecs); if (!started) return false; - if (msecs != -1) - msecs -= stopWatch.elapsed(); + msecs = qt_subtract_from_timeout(msecs, stopWatch.elapsed()); } return d->waitForFinished(msecs); -- cgit v1.2.3