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



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.