diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index ec3e6a1916e..0ca1c672499 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -1720,31 +1720,19 @@ bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase * */ /*! - \fn template bool QMetaObject::invokeMethod(QObject *context, Functor function, Qt::ConnectionType type, FunctorReturnType *ret) + \fn template bool QMetaObject::invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type, FunctorReturnType *ret) + \fn template bool QMetaObject::invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret) \since 5.10 - \threadsafe - \overload Invokes the \a function in the event loop of \a context. \a function can be a functor or a pointer to a member function. Returns \c true if the function could be invoked. Returns \c false if there is no such function or the parameters did not match. The return value of the function call is placed in \a ret. -*/ -/*! - \fn template bool QMetaObject::invokeMethod(QObject *context, Functor function, FunctorReturnType *ret) - - \since 5.10 - - \threadsafe - \overload - - Invokes the \a function in the event loop of \a context using the connection type Qt::AutoConnection. - \a function can be a functor or a pointer to a member function. Returns \c true if the function could - be invoked. Returns \c false if there is no such member or the parameters did not match. - The return value of the function call is placed in \a ret. + If \a type is set, then the function is invoked using that connection type. Otherwise, + Qt::AutoConnection will be used. */ /*! diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 28b4e368fe8..88b5437683c 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -406,55 +406,29 @@ struct Q_CORE_EXPORT QMetaObject #ifdef Q_QDOC template - static bool invokeMethod(QObject *context, Functor function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr); + static bool invokeMethod(QObject *context, Functor &&function, Qt::ConnectionType type = Qt::AutoConnection, FunctorReturnType *ret = nullptr); template - static bool invokeMethod(QObject *context, Functor function, FunctorReturnType *ret); + static bool invokeMethod(QObject *context, Functor &&function, FunctorReturnType *ret); #else - // invokeMethod() for member function pointer + // invokeMethod() for member function pointer or function pointer template - static typename std::enable_if::IsPointerToMemberFunction - && !std::is_convertible::value - && QtPrivate::FunctionPointer::ArgumentCount == 0, bool>::type - invokeMethod(typename QtPrivate::FunctionPointer::Object *object, - Func function, + static typename std::enable_if::ArgumentCount == 0, bool>::type + invokeMethod(typename QtPrivate::ContextTypeForFunctor::ContextType *object, + Func &&function, Qt::ConnectionType type = Qt::AutoConnection, typename QtPrivate::FunctionPointer::ReturnType *ret = nullptr) { - return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs(function), type, ret); + return invokeMethodImpl(object, QtPrivate::makeSlotObject(std::forward(function)), type, ret); } template - static typename std::enable_if::IsPointerToMemberFunction - && !std::is_convertible::value - && QtPrivate::FunctionPointer::ArgumentCount == 0, bool>::type - invokeMethod(typename QtPrivate::FunctionPointer::Object *object, - Func function, + static typename std::enable_if::ArgumentCount == 0, bool>::type + invokeMethod(typename QtPrivate::ContextTypeForFunctor::ContextType *object, + Func &&function, typename QtPrivate::FunctionPointer::ReturnType *ret) { - return invokeMethodImpl(object, new QtPrivate::QSlotObjectWithNoArgs(function), Qt::AutoConnection, ret); - } - - // invokeMethod() for function pointer (not member) - template - static typename std::enable_if::IsPointerToMemberFunction - && !std::is_convertible::value - && QtPrivate::FunctionPointer::ArgumentCount == 0, bool>::type - invokeMethod(QObject *context, Func function, - Qt::ConnectionType type = Qt::AutoConnection, - typename QtPrivate::FunctionPointer::ReturnType *ret = nullptr) - { - return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn(function), type, ret); - } - - template - static typename std::enable_if::IsPointerToMemberFunction - && !std::is_convertible::value - && QtPrivate::FunctionPointer::ArgumentCount == 0, bool>::type - invokeMethod(QObject *context, Func function, - typename QtPrivate::FunctionPointer::ReturnType *ret) - { - return invokeMethodImpl(context, new QtPrivate::QFunctorSlotObjectWithNoArgsImplicitReturn(function), Qt::AutoConnection, ret); + return invokeMethod(object, std::forward(function), Qt::AutoConnection, ret); } // invokeMethod() for Functor