[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] findChild(Person, "person") for QML object fails?
From:       <bootch () nc ! rr ! com>
Date:       2014-10-24 9:11:15
Message-ID: 20141024091115.XMS6R.183015.root () cdptpa-web15
[Download RAW message or body]

Simple demo of bug attached.

Also reporting the same bug:  \
http://stackoverflow.com/questions/16329622/findchild-returns-none-with-custom-widget


["testFindChild.py" (text/x-python)]

'''
Demonstrate a bug? in findChild: fails to find a child that findChildren() shows does exist.

There is another report of this bug? at 
http://stackoverflow.com/questions/16329622/findchild-returns-none-with-custom-widget
so although this example uses QML, the bug might be more general.
'''
import sys

from PyQt5.QtCore import QObject,QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtQml import qmlRegisterType
from PyQt5.QtQuick import QQuickView, QQuickItem


class Person(QObject):
    
    def __init__(self, parent=None):
        super().__init__(parent)
        
        
def main():
    print("start")
    app = QApplication(sys.argv)
    qmlRegisterType(Person, 'People', 1, 0, 'Person')
    v = QQuickView(QUrl("testFindChild.qml"))
    qmlRoot = v.rootObject()
    assert isinstance(qmlRoot, QQuickItem)
    assert isinstance(qmlRoot, QObject)
    dumpQMLComponents(qmlRoot)
    result = qmlRoot.findChild(Person, "person")
    assert result is not None
    
    sys.exit(app.exec_())

def dumpQMLComponents(root):
    children = root.findChildren(QObject)
    for item in children:
      # Note the QML id property is NOT the objectName
      print(item, item.objectName())
      if isinstance(item, Person) and item.objectName() == "person":
        print("Object of type: Person having name: person")
        
main()
["testFindChild.qml" (application/octet-stream)]
[Attachment #5 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic