Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Hierarchal or nested model properties are accessible in QML
Qt 6.11 is out! See what's new in the release blog

Hierarchal or nested model properties are accessible in QML

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 846 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bootchk
    wrote on last edited by
    #1

    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++.

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved