History

audit use of QTimer intervals to make sure we're using Qt::PreciseTimer when appropriate

Brad Hefta-Gaub committed 9 years ago

Commit a72f6011 parent b56a15b15 files · +35 −21Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 15 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+6−0
@@ -1087,6 +1087,12 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int · 1086 unmodified lines
10871087 QTimer* newTimer = new QTimer(this);
10881088 newTimer->setSingleShot(isSingleShot);
10891089
1090+ // The default timer type is not very accurate below about 200ms http://doc.qt.io/qt-5/qt.html#TimerType-enum
1091+ static const int MIN_TIMEOUT_FOR_COARSE_TIMER = 200;
1092+ if (intervalMS < MIN_TIMEOUT_FOR_COARSE_TIMER) {
1093+ newTimer->setTimerType(Qt::PreciseTimer);
1094+ }
1095+
10901096 connect(newTimer, &QTimer::timeout, this, &ScriptEngine::timerFired);
10911097
10921098 // make sure the timer stops when the script does