List property is an empty object in Component.onCompleted [solved]
-
wrote on 21 Mar 2011, 17:19 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 JsonItem {
id: mongoDatabaseproperty 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: listviewMongoDB { 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.
-
wrote on 21 Mar 2011, 18:50 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/2