Details
Description
I noticed the following when trying to invoke object methods directly from PySide6 using QMetaObject::invokeMethod() and QMetaMethod::invoke() in a generic way. The context is to call an abitrary method this way, which may have various return types:
- Q_ARG and Q_RETURN_ARG yield QGeneric[Return]ArgumentHolders, respectively. There is no direct method to get the Pythonic value back out of these structures.
- The Holders can be converted to QGenericArgument and QGenericReturnArgument (which we also can't get the Pythonic value back out of).
- QMetaObject::invokeMethod with the ...Holder types offers exactly what I need here: a way to call a method and yield an arbitrary Python object (converts the generic return argument back to the correct Pythonic object type under the hood"). But:
- This invokeMethod variant only allows for max. 3 arguments to be passed, whereas the non-...Holder variants offer up to about 10.
- FYI, the return arg conversion is implemented in
static PyObject *invokeMethodHelper (qtcore.cpp) - This seems to be the only method in the PySide API that does this automatic conversion.
- QMetaMethod::invoke doesn't have any interface which offers the automatic return type conversion.
Thus, it seems to me it is not possible to invoke a method generically if it has more than 3 arguments and a return value.
My suggestion would be to offer a direct conversion function which takes a QGeneric[Return]Argument and yields the correct Python value. Basically implementing the same conversion which is already being done now in static PyObject *invokeMethodHelper (qtcore.cpp).
This way, it can also be used with QMetaMethod, which I am assuming is faster than invokeMethod by name.
Attachments
Issue Links
- relates to
-
PYSIDE-1898 QMetaObject.invokeMethod with arguments not possible
- Closed
For Gerrit Dashboard: PYSIDE-2500 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
514982,4 | shiboken6: Simplify spaces in function signatures | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
515017,10 | Fix QMetaObject method invocation to accept all of the 10 arguments | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
515068,5 | Add QMetaMethod::invoke() | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
515319,2 | shiboken6: Simplify spaces in function signatures | 6.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
515392,2 | Fix QMetaObject method invocation to accept all of the 10 arguments | 6.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |
515397,2 | Add QMetaMethod::invoke() | 6.6 | pyside/pyside-setup | Status: MERGED | +2 | 0 |