[PyQt] Invoke function QML with arguments

Phil Thompson phil at riverbankcomputing.com
Wed Feb 19 19:03:10 GMT 2014


On 19-02-2014 6:18 pm, Charlie Gentil wrote:
> Hello,
>
> I want to invoke a function from QML Python. I use this:
>
> obj=app.rootObjects()
>
> myObject=obj[0].findChild(QObject,'myObj')
>
> QMetaObject.invokeMethod(myObject,"myTest",Qt.DirectConnection)
>
> It works fine, but now I have to pass arguments.
>
> I tried this:
>
> obj=app.rootObjects()
>
> myObject=obj[0].findChild(QObject,'myObject')
>
> QMetaObject.invokeMethod(myObject,"myTest",Qt.DirectConnection,
> Q_ARG(int, 1020
>
> My QML function :
>
> functionmyTest(x){
>
>  console.log(x)
>
> }
>
> But I have this error in return:
>
> QMetaObject::invokeMethod: No such method
> MyQML_QMLTYPE_100::myTest(int)
>
> QMetaObject.invokeMethod(myObject, "myTest", Qt.DirectConnection,
> Q_ARG(int, 1020))
>
> RuntimeError: QMetaObject.invokeMethod() call failed
>
> Can you help me?
>
> In advance thank you
>
> Charlie

Can you provide a short, complete script that demonstrates the problem?

Phil


More information about the PyQt mailing list