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

QTimer::singleShot() requires a non-const context

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.12.0
    • 5.5.1, 5.11.1
    • Core: Event loop
    • None
    • 491e427bb2d3cafccbb26d2ca3b7e128d786a564

    Description

      The documentation of QTimer::singleShot() states that the context/receiver should be a const pointer to QObject. This is consistent with e.g. QObject::connect().

      However, in reality the overloads taking a functor require a non-const pointer, which is both inconvenient and against the documentation and standard practice.

      Looking at qtimer.h, I see this:

      // singleShot to a functor or function pointer (with context)
      template <typename Duration, typename Func1>
      static inline typename std::enable_if<!QtPrivate::FunctionPointer<Func1>::IsPointerToMemberFunction && !std::is_same<const char*, Func1>::value, void>::type
      singleShot(Duration interval, QObject *context, Func1 slot)
      {
          singleShot(interval, defaultTypeFor(interval), context, std::move(slot));
      }

      So this seems to be a bug in the method signature/implementation.

      Attachments

        Issue Links

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

          Activity

            People

              thiago Thiago Macieira
              sputnick Manuel Nickschas
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes