Details
-
Suggestion
-
Resolution: Fixed
-
P3: Somewhat important
-
None
-
None
-
-
3
-
2c8690370 (dev), d0968b6dd (6.6)
-
Foundation PM Staging
Description
Documentation for QTimer::start(interval) says that it will trigger the timer with the given interval. It is however not explicitly explained that this will apply also for subsequent calls of QTimer::start(). In other words, it should be explicitly said that QTimer::start(interval); is equivalent to QTimer::setInterval(interval); followed by QTimer::start();.
See a snippet of confusing code:
#include <QCoreApplication> #include <QDebug> #include <QElapsedTimer> #include <QEventLoop> #include <QTimer> int main(int argc, char **argv) { QCoreApplication app(argc, argv); QElapsedTimer t; QTimer timer; timer.setSingleShot(true); timer.setInterval(1000); QEventLoop e; QObject::connect(&timer, &QTimer::timeout, &e, &QEventLoop::quit); t.start(); timer.start(2000); // this is clear, it will trigger in 2000 ms e.exec(); qDebug() << t.elapsed() << "ms"; t.start(); timer.start(); // but this is unclear - will it trigger in 1000 or 2000 ms? e.exec(); qDebug() << t.elapsed() << "ms"; // ... and now we can see it was 2000 ms }