[PyQt] Invoke function QML with arguments

Charlie Gentil ceg at redaction-developpez.com
Wed Feb 19 18:18:10 GMT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140219/23a24e00/attachment.html>


More information about the PyQt mailing list