diff options
| author | Ahmad Samir <a.samirh78@gmail.com> | 2024-08-28 22:17:14 +0300 |
|---|---|---|
| committer | Ahmad Samir <a.samirh78@gmail.com> | 2024-09-05 19:50:59 +0300 |
| commit | 87030778969165a285af2d919d6d7293e8078b6a (patch) | |
| tree | d47fd66a0bbe765e5e92b9e04da3648fbe572d4f /src/corelib/kernel/qtimer.cpp | |
| parent | 1666ce930b980ec73f01b038eb8d1a2a7b180ea4 (diff) | |
QTimer: QChronoTimer isn't necessarily going to supersede QTimer
... since no consensus has been reached about what to do in Qt7 (whether
to fold QChronoTimer back into QTimer or let QTimer be as-is to not
break any existing code and use QChronoTimer in new code).
Pick-to: 6.8
Task-number: QTBUG-128426
Change-Id: I7d09b803b4f0df3ea7f48a5d900d0ae4be721d7b
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/kernel/qtimer.cpp')
| -rw-r--r-- | src/corelib/kernel/qtimer.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/corelib/kernel/qtimer.cpp b/src/corelib/kernel/qtimer.cpp index 328bcd0ee2f..54a19c30503 100644 --- a/src/corelib/kernel/qtimer.cpp +++ b/src/corelib/kernel/qtimer.cpp @@ -74,13 +74,6 @@ QT_BEGIN_NAMESPACE more and more platforms, we expect that zero-millisecond QTimer objects will gradually be replaced by \l{QThread}s. - \note Since Qt 6.8 this class is superseded by \l{QChronoTimer}. - The maximum interval QTimer supports is limited by the number of - milliseconds that would fit in an \c int (which is around 24 days); - whereas QChronoTimer stores its interval as \c std::chrono::nanoseconds - (which raises that limit to ±292 years), that is, there is - less chance of integer overflow with QChronoTimer. - \section1 Accuracy and Timer Resolution The accuracy of timers depends on the underlying operating system @@ -103,7 +96,15 @@ QT_BEGIN_NAMESPACE \section1 Alternatives to QTimer - An alternative to using QTimer is to call QObject::startTimer() + Qt 6.8 introduced QChronoTimer. The main difference between the two + classes, is that QChronoTimer supports a larger interval range and a + higher precision (\c std::chrono::nanoseconds). For QTimer the maximum + supported interval is ±24 days, whereas for QChronoTimer it is ±292 + years (less chances of interger overflow with intervals longer than + \c std::numeric_limits<int>::max()). If you only need millisecond + resolution and ±24 days range, you can continue to use QTimer. + + Another alternative is to call QObject::startTimer() for your object and reimplement the QObject::timerEvent() event handler in your class (which must inherit QObject). The disadvantage is that timerEvent() does not support such |
