Hierarchal or nested model properties are accessible in QML



  • This is not a question, just a fact that might be useful.

    Suppose you have an object with a property that is an object with its own properties (PyQt code):

    @
    class Person(QObject):
    def init()
    self._name ="foo"

    @pyqtProperty(QString) # getter
    def name(self):
    return self._name

    class Clan(QObject):
    def init()
    self._person = Person()

    @pyqtProperty(Person) # getter
    def person(self):
    return self._person
    @

    Then if you expose an instance of that to QML, you can use dot notation (qualification) to access that structure:

    @
    import Clan 1.0

    Clan {
    id: clan
    onComponentCreated: {
    console.log("clan.person:", clan.person)
    console.log("clan.person.name:", clan.person.name)
    }
    }
    @

    From the documentation, it wasn't clear to me that this should work, I was concerned that Javascript would prevent it. I suppose Javascript is not even relevant here.

    I also want to know whether Python dictionaries could be used in QML. I am supposing not, since dictionaries are not part of C++.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.