[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QMetaObject.invokeMethod with C++/QML type
From:       Alexander_Rössler <alexander () roessler ! systems>
Date:       2018-09-21 21:36:45
Message-ID: 1537565524.local-14d30531-4889-v1.4.2-f587b7b7 () getmailspring ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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
qan::Node*

trying
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@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@riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt
> 


[Attachment #5 (text/html)]

<div>I investigated a little bit more:</div><br><div>        meta = \
self._graph.metaObject()</div><div>        print(meta.methodCount(), \
meta.methodOffset())</div><div>        for i in range(meta.methodOffset(), \
meta.methodCount()):</div><div>            method = meta.method(i)</div><div>            \
print(method.methodSignature(), method.returnType(), \
QMetaType.typeName(method.returnType()))</div><br><div>Which showed me the Qt \
type</div><div>qan::Node*</div><br><div>trying</div><br><div>return_val = \
QMetaObject.invokeMethod(</div><div>            self._graph, "insertNode", Qt.DirectConnection, \
Q_RETURN_ARG('qan::Node*')</div><div>        )</div><br><div>I get a more descriptive \
error:</div><div>TypeError: C++ type 'qan::Node*' is not supported as a Q_RETURN_ARG() \
type</div><br><div>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?</div><br><div>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.</div><br><div class="gmail_quote_attribution">On Sep 21 \
2018, at 11:10 pm, Alexander Rössler &lt;alexander@roessler.systems&gt; \
wrote:</div><blockquote><br><div><div>I want to call a C++/QML method from PyQt via \
QMetaObject.invokeMethod like so:</div><br><div>return_val = \
QMetaObject.invokeMethod(</div><div>self._graph, "insertNode", Qt.DirectConnection, \
Q_RETURN_ARG(QVariant)</div><div>)</div><br><div>The method I call is <a \
href="https://github.com/cneben/QuickQanava/blob/master/src/qanGraph.h#L335" \
title="https://github.com/cneben/QuickQanava/blob/master/src/qanGraph.h#L335">https://github.com/cneben/QuickQanava/blob/master/src/qanGraph.h#L335</a> \
which returns a custom QML registered QObject based type.</div><br><div>However, when I try to \
invoke the method Q_RETURN_ARG it fails.</div><div>FATAL ERROR: An unexpected error \
occurred:</div><div>QMetaObject.invokeMethod() call failed</div><br><div>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.</div><br><div>Any ideas \
why this doesn't work and how I could use the returned QObject without "siping" the whole \
library?</div><br><div>Alex</div><div>_______________________________________________</div><div>PyQt \
mailing list PyQt@riverbankcomputing.com</div><div>https://www.riverbankcomputing.com/mailman/listinfo/pyqt</div></div></blockquote>



[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic