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

QTimer::singleShot can crash with 0ms interval and a functor callback

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.6.0 RC
    • 5.5.0
    • Core: Other
    • None
    • Change-Id: Iab73d02933635821b8d1ca1ff3d53e92eca85834

    Description

      Calling QTimer::singleShot with a 0ms interval, a functor callback and a context object in another thread can cause a crash. The following code triggers the crash when left to run for a relatively short period of time:

      #include <QGuiApplication>
      #include <QTimer>
      #include <QThread>
      
      int main(int argc, char *argv[])
      {
          QGuiApplication a(argc, argv);
      
          QThread thread;
          thread.start();
      
          QObject* o = new QObject();
          o->moveToThread(&thread);
      
          QTimer t;
          t.setInterval(0);
      
          QObject::connect(&t, &QTimer::timeout, [&]() {
              QTimer::singleShot(0, o, []() {});
          });
      
          t.start();
      
          return a.exec();
      }
      

      Attachments

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

        Activity

          People

            juturune Juha Turunen
            juturune Juha Turunen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes