[PyQt] Invoke function QML with arguments
Charlie Gentil
ceg at redaction-developpez.com
Fri Feb 21 17:56:48 GMT 2014
Le vendredi 21 février 2014, 17:25:27 Phil Thompson a écrit :
> 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
>
> You need to use Q_ARG(QVariant, 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
>
> A more readable solution would be to do...
>
> myObject.myTest(1020)
>
> Phil
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
Hi,
It was really too simple ... I did not think at all.
thank you very much
Charlie
More information about the PyQt
mailing list