diff --git a/src/corelib/kernel/qmetaobject.cpp b/src/corelib/kernel/qmetaobject.cpp index 188f4da5c3..c6ab79718b 100644 --- a/src/corelib/kernel/qmetaobject.cpp +++ b/src/corelib/kernel/qmetaobject.cpp @@ -1426,8 +1426,8 @@ printMethodNotFoundWarning(const QMetaObject *meta, QLatin1StringView name, qsiz } /*! - \fn template bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QMetaMethodReturnArgument r, Args &&... args) - \fn template bool QMetaObject::invokeMethod(QObject *obj, const char *member, QMetaMethodReturnArgument r, Args &&... args) + \fn template bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument r, Args &&... args) + \fn template bool QMetaObject::invokeMethod(QObject *obj, const char *member, QTemplatedMetaMethodReturnArgument r, Args &&... args) \fn template bool QMetaObject::invokeMethod(QObject *obj, const char *member, Qt::ConnectionType type, Args &&... args) \fn template bool QMetaObject::invokeMethod(QObject *obj, const char *member, Args &&... args) \since 6.5 @@ -1437,11 +1437,12 @@ printMethodNotFoundWarning(const QMetaObject *meta, QLatin1StringView name, qsiz obj. Returns \c true if the member could be invoked. Returns \c false if there is no such member or the parameters did not match. - For the overloads with a QMetaMethodReturnArgument parameter, the return - value of the \a member function call is placed in \a ret. For the overloads - without such a member, the return value of the called function (if any) - will be discarded. QMetaMethodReturnArgument is an internal type you should - not use directly. Instead, use the qReturnArg() function. + For the overloads with a QTemplatedMetaMethodReturnArgument parameter, the + return value of the \a member function call is placed in \a ret. For the + overloads without such a member, the return value of the called function + (if any) will be discarded. QTemplatedMetaMethodReturnArgument is an + internal type you should not use directly. Instead, use the qReturnArg() + function. The overloads with a Qt::ConnectionType \a type parameter allow explicitly selecting whether the invocation will be synchronous or not: @@ -2379,20 +2380,21 @@ QMetaMethod QMetaMethod::fromSignalImpl(const QMetaObject *metaObject, void **si } /*! - \fn template bool QMetaMethod::invoke(QObject *obj, Qt::ConnectionType type, QMetaMethodReturnArgument ret, Args &&... arguments) const + \fn template bool QMetaMethod::invoke(QObject *obj, Qt::ConnectionType type, QTemplatedMetaMethodReturnArgument ret, Args &&... arguments) const \fn template bool QMetaMethod::invoke(QObject *obj, Qt::ConnectionType type, Args &&... arguments) const - \fn template bool QMetaMethod::invoke(QObject *obj, QMetaMethodReturnArgument ret, Args &&... arguments) const + \fn template bool QMetaMethod::invoke(QObject *obj, QTemplatedMetaMethodReturnArgument ret, Args &&... arguments) const \fn template bool QMetaMethod::invoke(QObject *obj, Args &&... arguments) const \since 6.5 Invokes this method on the object \a object. Returns \c true if the member could be invoked. Returns \c false if there is no such member or the parameters did not match. - For the overloads with a QMetaMethodReturnArgument parameter, the return - value of the \a member function call is placed in \a ret. For the overloads - without such a member, the return value of the called function (if any) - will be discarded. QMetaMethodReturnArgument is an internal type you should - not use directly. Instead, use the qReturnArg() function. + For the overloads with a QTemplatedMetaMethodReturnArgument parameter, the + return value of the \a member function call is placed in \a ret. For the + overloads without such a member, the return value of the called function + (if any) will be discarded. QTemplatedMetaMethodReturnArgument is an + internal type you should not use directly. Instead, use the qReturnArg() + function. The overloads with a Qt::ConnectionType \a type parameter allow explicitly selecting whether the invocation will be synchronous or not: @@ -2819,7 +2821,7 @@ auto QMetaMethodInvoker::invokeImpl(QMetaMethod self, void *target, */ /*! - \fn template bool QMetaMethod::invokeOnGadget(void *gadget, QMetaMethodReturnArgument ret, Args &&... arguments) const + \fn template bool QMetaMethod::invokeOnGadget(void *gadget, QTemplatedMetaMethodReturnArgument ret, Args &&... arguments) const \fn template bool QMetaMethod::invokeOnGadget(void *gadget, Args &&... arguments) const \since 6.5 @@ -2830,11 +2832,11 @@ auto QMetaMethodInvoker::invokeImpl(QMetaMethod self, void *target, The invocation is always synchronous. - For the overload with a QMetaMethodReturnArgument parameter, the return - value of the \a member function call is placed in \a ret. For the overload - without it, the return value of the called function (if any) will be - discarded. QMetaMethodReturnArgument is an internal type you should not use - directly. Instead, use the qReturnArg() function. + For the overload with a QTemplatedMetaMethodReturnArgument parameter, the + return value of the \a member function call is placed in \a ret. For the + overload without it, the return value of the called function (if any) will + be discarded. QTemplatedMetaMethodReturnArgument is an internal type you + should not use directly. Instead, use the qReturnArg() function. \warning this method will not test the validity of the arguments: \a gadget must be an instance of the class of the QMetaObject of which this QMetaMethod diff --git a/src/corelib/kernel/qmetaobject.h b/src/corelib/kernel/qmetaobject.h index c51922e659..4e52e854d9 100644 --- a/src/corelib/kernel/qmetaobject.h +++ b/src/corelib/kernel/qmetaobject.h @@ -135,13 +135,13 @@ public: } #endif - template + template #ifdef Q_QDOC bool #else QtPrivate::Invoke::IfNotOldStyleArgs #endif - invoke(QObject *obj, Qt::ConnectionType c, QMetaMethodReturnArgument r, + invoke(QObject *obj, Qt::ConnectionType c, QTemplatedMetaMethodReturnArgument r, Args &&... arguments) const { auto h = QtPrivate::invokeMethodHelper(r, std::forward(arguments)...); @@ -157,16 +157,16 @@ public: #endif invoke(QObject *obj, Qt::ConnectionType c, Args &&... arguments) const { - return invoke(obj, c, QMetaMethodReturnArgument{}, std::forward(arguments)...); + return invoke(obj, c, QTemplatedMetaMethodReturnArgument{}, std::forward(arguments)...); } - template + template #ifdef Q_QDOC bool #else QtPrivate::Invoke::IfNotOldStyleArgs #endif - invoke(QObject *obj, QMetaMethodReturnArgument r, Args &&... arguments) const + invoke(QObject *obj, QTemplatedMetaMethodReturnArgument r, Args &&... arguments) const { return invoke(obj, Qt::AutoConnection, r, std::forward(arguments)...); } @@ -182,13 +182,13 @@ public: return invoke(obj, Qt::AutoConnection, std::forward(arguments)...); } - template + template #ifdef Q_QDOC bool #else QtPrivate::Invoke::IfNotOldStyleArgs #endif - invokeOnGadget(void *gadget, QMetaMethodReturnArgument r, Args &&... arguments) const + invokeOnGadget(void *gadget, QTemplatedMetaMethodReturnArgument r, Args &&... arguments) const { auto h = QtPrivate::invokeMethodHelper(r, std::forward(arguments)...); return invokeImpl(*this, gadget, Qt::ConnectionType(-1), h.parameterCount(), @@ -203,7 +203,7 @@ public: #endif invokeOnGadget(void *gadget, Args &&... arguments) const { - return invokeOnGadget(gadget, QMetaMethodReturnArgument{}, std::forward(arguments)...); + return invokeOnGadget(gadget, QTemplatedMetaMethodReturnArgument{}, std::forward(arguments)...); } inline bool isValid() const { return mobj != nullptr; } diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h index 42f02b9706..e024695a0b 100644 --- a/src/corelib/kernel/qobjectdefs.h +++ b/src/corelib/kernel/qobjectdefs.h @@ -142,6 +142,12 @@ struct QMetaMethodReturnArgument void *data; }; +template +struct QTemplatedMetaMethodReturnArgument : QMetaMethodReturnArgument +{ + using Type = T; +}; + namespace QtPrivate { namespace Invoke { #if QT_VERSION <= QT_VERSION_CHECK(7, 0, 0) @@ -164,7 +170,8 @@ template inline QMetaMethodArgument argument(const char *name, cons } } -template inline QMetaMethodReturnArgument returnArgument(const char *name, T &t) +template +inline QTemplatedMetaMethodReturnArgument returnArgument(const char *name, T &t) { return { qMetaTypeInterfaceForType(), name, std::addressof(t) }; } @@ -217,7 +224,7 @@ template inline auto invokeMethodHelper(QMetaMethodReturnArgu } // namespace QtPrivate template void qReturnArg(const T &&) = delete; -template inline QMetaMethodReturnArgument qReturnArg(T &data) +template inline QTemplatedMetaMethodReturnArgument qReturnArg(T &data) { return QtPrivate::Invoke::returnArgument(nullptr, data); } @@ -354,14 +361,14 @@ struct Q_CORE_EXPORT QMetaObject } #endif // Qt < 7.0 - template static + template static #ifdef Q_QDOC bool #else QtPrivate::Invoke::IfNotOldStyleArgs #endif invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c, - QMetaMethodReturnArgument r, Args &&... arguments) + QTemplatedMetaMethodReturnArgument r, Args &&... arguments) { auto h = QtPrivate::invokeMethodHelper(r, std::forward(arguments)...); return invokeMethodImpl(obj, member, c, h.parameterCount(), h.parameters.data(), @@ -376,17 +383,17 @@ struct Q_CORE_EXPORT QMetaObject #endif invokeMethod(QObject *obj, const char *member, Qt::ConnectionType c, Args &&... arguments) { - QMetaMethodReturnArgument r = {}; + QTemplatedMetaMethodReturnArgument r = {}; return invokeMethod(obj, member, c, r, std::forward(arguments)...); } - template static + template static #ifdef Q_QDOC bool #else QtPrivate::Invoke::IfNotOldStyleArgs #endif - invokeMethod(QObject *obj, const char *member, QMetaMethodReturnArgument r, + invokeMethod(QObject *obj, const char *member, QTemplatedMetaMethodReturnArgument r, Args &&... arguments) { return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward(arguments)...); @@ -400,7 +407,7 @@ struct Q_CORE_EXPORT QMetaObject #endif invokeMethod(QObject *obj, const char *member, Args &&... arguments) { - QMetaMethodReturnArgument r = {}; + QTemplatedMetaMethodReturnArgument r = {}; return invokeMethod(obj, member, Qt::AutoConnection, r, std::forward(arguments)...); }