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. List property is an empty object in Component.onCompleted [solved]
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 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 21 Mar 2011, 17:19 last edited by
    #1

    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
    0
    • M Offline
      M Offline
      manuelsch
      wrote on 21 Mar 2011, 18:50 last edited by
      #2

      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
      0

      1/2

      21 Mar 2011, 17:19

      • Login

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