From 4e1ad49998cf782ccc88e7e80fbd05c722658a16 Mon Sep 17 00:00:00 2001 From: "Bradley T. Hughes" Date: Wed, 21 Dec 2011 11:33:07 +0100 Subject: [PATCH] Make QTimer::singleShot use Qt::PreciseTimer for lower timeouts. CoarseTimers are worst in their first firing, so we prefer a PreciseTimer for something that happens only once. If the timeout is too big, we use a CoarseTimer anyway (current threshold is 2000ms). Author: Thiago Macieira Change-Id: I30b20acf506e442cd58126abfe3a4d70fc13b075 Reviewed-by: Thiago Macieira --- src/corelib/kernel/qtimer.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index e89abad..8bf65c3 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -317,7 +317,10 @@ QT_END_INCLUDE_NAMESPACE void QTimer::singleShot(int msec, QObject *receiver, const char *member) { - singleShot(msec, Qt::CoarseTimer, receiver, member); + // coarse timers are worst in their first firing + // so we prefer a high precision timer for something that happens only once + // unless the timeout is too big, in which case we go for coarse anyway + singleShot(msec, msec >= 2000 ? Qt::CoarseTimer : Qt::PreciseTimer, receiver, member); } /*! \overload -- 2.7.4