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. Component initializiation order
QtWS25 Last Chance

Component initializiation order

Scheduled Pinned Locked Moved QML and Qt Quick
4 Posts 2 Posters 1.9k Views
  • 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.
  • M Offline
    M Offline
    manuelsch
    wrote on last edited by
    #1

    Hi,

    I have these lines of code:
    @
    import Qt 4.7

    ListView {
    id: listview
    width: 300
    height: 500

    MongoDB {
        id: db
        name: "testdb"
        host: "localhost"
    
        collections: [
            MongoCollection {
                    id: mythings
                    name: "things"
            }
        ]
    }
    
    delegate: mydelegate
    model: mythings.find({})
    
    Component {
        id: mydelegate
        Text { text: obj.toString() }
    }
    

    }
    @
    And my MongoDB is a QObject implemented in C++ and implementing the QDeclarativeParserStatus-interface to be able to react wait until all properties of MongoDB are set, so that I know to which host to connect.
    The problem is the line
    @
    model: mythings.find({})
    @
    This line is called before MongoDB's componentComplete() is called. That means that the find({}) function is called before I can determine to which host to connect.

    Can anybody tell me how to do this in the correct order?
    Or am I generally not getting the point here?

    Cheers!

    Manuel

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      @Component.onCompleted: listview.model = mythings.find({})@
      Should set the model after MongoDB is set up.

      Another option might be to expose a MongoQuery object that provides the results of a search as a property (which could then notify once it had a result).

      One of the problems with using C++ functions from QML (in this case find()) is they don't always work well in bindings -- there is no way to say "call this function again, because the results have changed". We're looking at adding something like this in future versions (similar to NOTIFY for properties), at which point your original code should work as well.

      Is your QML binding of MongoDB public? I'd love to have a look.

      Regards,
      Michael

      1 Reply Last reply
      0
      • M Offline
        M Offline
        manuelsch
        wrote on last edited by
        #3

        Thanks, Michael.

        Yes, it's quite a nice idea. It's currently in a very early development status - as you can see, but I think I will publish a proof of concept at this weekend.
        If I've done that, I'l post it here.

        Cheers,

        Manuel

        1 Reply Last reply
        0
        • M Offline
          M Offline
          manuelsch
          wrote on last edited by
          #4

          Hi Michael,

          have a look at "this thread":http://developer.qt.nokia.com/forums/viewthread/4574/ or "here for plugin the code":https://github.com/manuels/QtMongo/

          Cheers,

          Manuel

          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