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

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

XMLWordPrintable

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

      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.

        For Gerrit Dashboard: QTBUG-69800
        # Subject Branch Project Status CR V

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes