defining and calling QML functions directly from Python

Stefan Seefeld stefan at seefeld.name
Wed Sep 22 13:44:34 BST 2021


I'm trying to modify the example given in 
https://www.riverbankcomputing.com/static/Docs/PyQt5/qml.html by 
including a JS function in the `example.qml` file such that I can invoke 
that from Python.

Let's say I change `example.qml` to

import  People  1.0

Person  {
     name:  "Bob Jones"
     shoeSize:  12
     function greet() { console.log("Hello World !")}
}


I'm then trying to call the new method from Python, but neither 
`person.greet()` nor `QMetaObject.invokeMethod(person, 'greet')` work. 
What is the right way to access and call a QML function from Python ?

Thanks,

Stefan
-- 

       ...ich hab' noch einen Koffer in Berlin...

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210922/ebdd4f2c/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: .signature.png
Type: image/png
Size: 2754 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210922/ebdd4f2c/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: stefan.vcf
Type: text/x-vcard
Size: 4 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20210922/ebdd4f2c/attachment.vcf>


More information about the PyQt mailing list