Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid calling QMetaObject::invokeMethod in variadic form
Since Qt 6.5 there is a new variadic version of the QMetaObject::invokeMethod() method [0]. Generally this is a good idea, as this fixes the problem of being able to pass a maximum number of only 10 arguments to invokeMethod(). However for usage in GammaRay this poses a problem: When we call invokeObjectLocal() from within the inspected process, we can no longer just dump all arguments, as the variadic invokeMethod() version will then always attempt to call a version of the method with exactly 10 arguments of type GammaRay::MethodArgument [1]. The fact that the argument number is fixed (and usually wrong) is not the main problem here, as it could easily be worked around by adding 10 if branches that select the appropriate invokeMethod() with the correct arity. The more serious problem is that the argument type is always fixed to GammaRay::MethodArgument [2]. We can't easily work around this as Q_ARG() wrappers and similar shenanigans need the type at compile time, but we don't know the type at compile time. Luckily the non-variadic version of QMetaObject::invokeMethod still exists, so as a workaround we force the usage of the non-variadic version by explicitly passing the arguments as QGenericArgument. Note that this version of QMetaObject::invokeMethod is obsolete since Qt 6.5 and might be removed with Qt 7.0, in which case we need to find a better fix. As for the actual implementation in this patch, note that we need to store the MethodArgument first and can't just construct the QGenericArgument directly. Alternatively we could wrap every parameter in the function call to invokeMethod() with QGenericArgument(), but using a second array is a little bit cleaner code-wise. Fixes #777 Fixes #761 [0] https://codereview.qt-project.org/c/qt/qtbase/+/422745 [1] see #777 (comment) [2] e.g.: QMetaObject::invokeMethod: No such method GammaRay::ToolManagerClient::availableToolsResponse(GammaRay::MethodArgument) Candidates are: availableToolsResponse(QList<GammaRay::ToolData>)
- Loading branch information