[PyQt] QMetaObject.invokeMethod with C++/QML type

Alexander Rössler alexander at roessler.systems
Fri Sep 21 22:36:45 BST 2018

I investigated a little bit more:

meta = self._graph.metaObject()
print(meta.methodCount(), meta.methodOffset())
for i in range(meta.methodOffset(), meta.methodCount()):
method = meta.method(i)
print(method.methodSignature(), method.returnType(), QMetaType.typeName(method.returnType()))

Which showed me the Qt type

return_val = QMetaObject.invokeMethod(
self._graph, "insertNode", Qt.DirectConnection, Q_RETURN_ARG('qan::Node*')

I get a more descriptive error:
TypeError: C++ type 'qan::Node*' is not supported as a Q_RETURN_ARG() type

Which makes sense, since it's a C++ type. Are there any other ways to use the returned object from PyQt than to wrap the library with sip?
I already tried to wrap the library with sip, but I can't get it to work without causing segfaults. That's why I'm looking for simpler alternatives.
On Sep 21 2018, at 11:10 pm, Alexander Rössler <alexander at roessler.systems> wrote:
> I want to call a C++/QML method from PyQt via QMetaObject.invokeMethod like so:
> return_val = QMetaObject.invokeMethod(
> self._graph, "insertNode", Qt.DirectConnection, Q_RETURN_ARG(QVariant)
> )
> The method I call is https://github.com/cneben/QuickQanava/blob/master/src/qanGraph.h#L335 which returns a custom QML registered QObject based type.
> However, when I try to invoke the method Q_RETURN_ARG it fails.
> FATAL ERROR: An unexpected error occurred:
> QMetaObject.invokeMethod() call failed
> Without specifying a return type, invoking the method works. Since it's a type registered in the Qt meta object system, I expected that QVariant or QObject would work as return types.
> Any ideas why this doesn't work and how I could use the returned QObject without "siping" the whole library?
> Alex
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180921/825de9f3/attachment.html>

More information about the PyQt mailing list