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. Connect QObject properties to a QQmlComponent
Forum Updated to NodeBB v4.3 + New Features

Connect QObject properties to a QQmlComponent

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.3k 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.
  • 0 Offline
    0 Offline
    02JanDal
    wrote on last edited by
    #1

    Hello,

    I'm trying to create an application similar to Scratch (placing graphical blocks instead of writing text) for trying to get children interested in programming. I'd really like to do it in QtQuick for nice animations etc., and I think it should be fully doable.

    For getting the tree like structure I use something like "this":http://www.codeproject.com/Articles/664041/QML-QtQuick-TreeView-Model-Part-II , so each kind of delegate that has child items will end with a repeater.

    My problem right now is getting the C++ <-> QML bridge to work, I'm currently trying to have QObject subclasses contain the data as properties and one "delegate" property that returns a QQmlComponent, the root items are then put into a list and given to QML.

    The problem I'm currently having is connecting the data to the component (delegate), how would I do that?

    Thanks in advance,
    Jan

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      How do you set the model for the delegate(s)?
      if you set your custom delegate to any kind of QML model view it should work out of the box with the attached property "modelData" to access your properties?
      e.g:
      @
      Repeater {
      delegate: foo.delegate // where foo is your c++ QObject with the delegate property
      }
      @
      that's just an example but you should be able to access the poperties of the delegate inside the repeater now (with modelData.xyz where xyz is a property in your delegate)

      you can off course create your own view with an attached property like that or use a ListView or whatever has a model and delegate in the QtQuick components.

      I hope that is what you want ^^

      1 Reply Last reply
      0
      • 0 Offline
        0 Offline
        02JanDal
        wrote on last edited by
        #3

        Nice, using the modelData property I managed to create a C++ function that gives me the data object for the modelData object (I'd thought there would be some other way though).

        Thank you,
        Jan

        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