[PyQt] findChild(Person, "person") for QML object fails?

Phil Thompson phil at riverbankcomputing.com
Thu Oct 23 16:41:55 BST 2014


On 23/10/2014 4:03 pm, bootch at nc.rr.com wrote:
> QObject.findChildren() seems to show a child of the type Person (from
> pyqt QML example in the docs) and objectName=="person",
> but findChild(Person, "person") doesn't.
> 
> Here is a snippet of the code:
> 
>     self.dumpQMLComponents(qmlRoot)
> 
>     #result = qmlRoot.findChild(Person, "person")
>     result = qmlRoot.findChild(model.person.Person, "person")
>     assert result is not None
>     return result
> 
> 
>   def dumpQMLComponents(self, root):
>     children = root.findChildren(QObject)
>     for item in children:
>       # Note the QML id property is NOT the objectName
>       print(item, "name is:", item.objectName())
>       if isinstance(item, model.person.Person):
>         print("Is Person")
> 
> And a snippet of the printed output:
> 
> <PyQt5.QtQuick.QQuickItem object at 0xb2c064ac>
> <model.person.Person object at 0xb2c062b4> name is: person
> Is Person
> <PyQt5.QtCore.QObject object at 0xb2c064f4> name is:
> ...
>   File "/home/bootch/git/demoQMLPyQt/widgetApp/graphicsView.py", line
> 52, in findPicker
>     assert result is not None
> AssertionError
> 
> 
> Its no big deal, I will just workaround.
> Probably something I don't understand about Python types and C++ 
> casting.
> I can submit a complete small example.

Please do.

Phil


More information about the PyQt mailing list