Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-116218

docs do not explicitly say that QTimer::start(interval) actually changes the interval also for subsequent starts

    XMLWordPrintable

Details

    • All
    • 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
      }
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            vladimir.kraus Vladimir Kraus
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes