Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    List property is an empty object in Component.onCompleted [solved]

    QML and Qt Quick
    1
    2
    1741
    Loading More Posts
    • 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
      manuelsch last edited by

      Hi,

      I have defined a new Component in the file "MongoDB.qml"
      @import Qt 4.7
      import "MongoDB.js" as MongoDB
      import "../json/json2.js" as Json

      Item {
      id: mongoDatabase

      property string name
      property string host: "localhost"
      
      property list<MongoCollection> collections
      
      function stats() { return MongoDB.db.stats() }
      
      Component.onCompleted: {
          MongoDB.init(Mongo.init(host), name)
      
          console.log(Json.JSON.stringify(mongoDatabase.collections))
          console.log(mongoDatabase.collections)
      }
      

      }
      @
      And then I use this MongoDB component in my main QML file like this:
      @
      import "QtMongo"

      [...]
      ListView {
      id: listview

              MongoDB {
                  id: db
                  name: "testdb"
                  host: "localhost"
      
                  collections: [
                      MongoCollection {
                              id: mythings
                              name: "things"
                      }
                  ]
              }
      

      [...]
      @
      The problem is, that in MongoDB's Component.onCompleted the variable mongoDatabase.collections is always an empty object ("{}").
      Can anybody tell me why? From my point of view, it should be an array including a MongoCollection called mythings.

      Edit: the MongoDB.qml and MongoCollection.qml files are in the same directory (called "QtMongo") and my main QML file is in the parent directory.

      1 Reply Last reply Reply Quote 0
      • M
        manuelsch last edited by

        ahh, ok, I made it work:
        You cannot use a for-in-loop. Only for(i =0; i<collections.length;++i)-loop

        1 Reply Last reply Reply Quote 0
        • First post
          Last post