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

Cannot connect QTimer::timeout() to lambda function

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P1: Critical
    • 5.0.0 Beta 2
    • 5.0.0 Beta 1, 5.0.0 Beta 2, 5.0.0 RC 1, 5.0.0
    • Core: Event loop
    • None
    • OS X 10.7.5, clang 3.1 (mainline version via MacPorts), Qt 5 from git
    • 029cc40c2ac2f6f1013020f6af5e63b46a7a8317

    Description

      The following code snippet results in clang compiler error:

      	QTimer timer;
      	QObject::connect(&timer, &QTimer::timeout, [](){});
      

      Error:

      In file included from ../../Dropbox/Client2012/main.cpp:1:
      In file included from ../../Dropbox/Client2012/MainWindow.h:4:
      In file included from /Qt/5.0/qtbase/include/QtWidgets/QMainWindow:1:
      In file included from /Qt/5.0/qtbase/include/QtWidgets/qmainwindow.h:1:
      In file included from /Qt/5.0/qtbase/include/QtWidgets/../../src/widgets/widgets/qmainwindow.h:45:
      In file included from /Qt/5.0/qtbase/include/QtWidgets/qwidget.h:1:
      In file included from /Qt/5.0/qtbase/include/QtWidgets/../../src/widgets/kernel/qwidget.h:45:
      In file included from /Qt/5.0/qtbase/include/QtGui/qwindowdefs.h:1:
      In file included from /Qt/5.0/qtbase/include/QtGui/../../src/gui/kernel/qwindowdefs.h:46:
      In file included from /Qt/5.0/qtbase/include/QtCore/qobjectdefs.h:1:
      In file included from /Qt/5.0/qtbase/include/QtCore/../../src/corelib/kernel/qobjectdefs.h:47:
      In file included from /Qt/5.0/qtbase/include/QtCore/qobjectdefs_impl.h:1:
      /Qt/5.0/qtbase/include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:395:13: error: no matching function for call to object of type '<lambda at ../../Dropbox/Client2012/main.cpp:69:45>'
                  f((*reinterpret_cast<typename RemoveRef<SignalArgs>::Type *>(arg[I+1]))...), ApplyReturnValue<R>(arg[0]);
                  ^
      /Qt/5.0/qtbase/include/QtCore/../../src/corelib/kernel/qobjectdefs_impl.h:434:79: note: in instantiation of member function 'QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List<QTimer::QPrivateSignal>, void, <lambda at ../../Dropbox/Client2012/main.cpp:69:45> >::call' requested here
                  FunctorCall<typename Indexes<N>::Value, SignalArgs, R, Function>::call(f, arg);
                                                                                    ^
      /Qt/5.0/qtbase/include/QtCore/../../src/corelib/kernel/qobject_impl.h:193:17: note: in instantiation of function template specialization 'QtPrivate::Functor<<lambda at ../../Dropbox/Client2012/main.cpp:69:45>, 1>::call<QtPrivate::List<QTimer::QPrivateSignal>, void>' requested here
                      FuncType::template call<Args, R>(static_cast<QFunctorSlotObject*>(this_)->function, r, a);
                      ^
      /Qt/5.0/qtbase/include/QtCore/../../src/corelib/kernel/qobject_impl.h:202:71: note: in instantiation of member function 'QtPrivate::QFunctorSlotObject<<lambda at ../../Dropbox/Client2012/main.cpp:69:45>, 1, QtPrivate::List<QTimer::QPrivateSignal>, void>::impl' requested here
              explicit QFunctorSlotObject(const Func &f) : QSlotObjectBase(&impl), function(f) {}
                                                                            ^
      /Qt/5.0/qtbase/include/QtCore/../../src/corelib/kernel/qobject.h:285:32: note: in instantiation of member function 'QtPrivate::QFunctorSlotObject<<lambda at ../../Dropbox/Client2012/main.cpp:69:45>, 1, QtPrivate::List<QTimer::QPrivateSignal>, void>::QFunctorSlotObject' requested here
                                 new QtPrivate::QFunctorSlotObject<Func2, SignalType::ArgumentCount, typename SignalType::Arguments, typename SignalType::ReturnType>(slot),
                                     ^
      ../../Dropbox/Client2012/main.cpp:69:2: note: in instantiation of function template specialization 'QObject::connect<void (QTimer::*)(), <lambda at ../../Dropbox/Client2012/main.cpp:69:45> >' requested here
              QObject::connect(&timer, &QTimer::timeout, [](){});
              ^
      ../../Dropbox/Client2012/main.cpp:69:45: note: candidate function not viable: requires 0 arguments, but 1 was provided
              QObject::connect(&timer, &QTimer::timeout, [](){});
                                                         ^
      ../../Dropbox/Client2012/main.cpp:69:45: note: conversion candidate of type 'void (*)()'
      

      This is using mainline (real) clang 3.1. with:

      QMAKE_CXXFLAGS += -std=c++11
      

      Attachments

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

        Activity

          People

            stephen.kelly Stephen Kelly (Unused account) (Inactive)
            stephenju Stephen Chu
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes