On<property name>Changed: undefined property



  • Hi,

    corresponding to "the documentation":http://doc.qt.nokia.com/4.7-snapshot/qmlevents.html, on can catch changes of properties using the <property_name>Changed signal

    I tried to implement this for the collection property of this object:
    @import QtQuick 1.1
    import "lib/json/json2.js" as Json

    ListModel {
    id: mongoQuery

    property MongoCollection collection
    property variant query
    property variant sort
    property int limit: -1
    property int skip: 0
    property bool snapshot: false
    property bool $returnKey: false
    property int $maxScan: -1
    property variant $min
    property variant $max
    property bool $showDiskLoc: false
    property variant $hin-t
    
    function update() {
        clear()
    
        var cursor = collection.find(query)
        console.log( Json.JSON.stringify(query) )
    
        if ($returnKey)
            cursor = cursor._addSpecial("$returnKey", $returnKey)
        if (snapshot)
            cursor = cursor.snapshot()
        if ($min)
            cursor = cursor._addSpecial("$min", $min)
        if ($max)
            cursor = cursor._addSpecial("$max", $max)
        if ($showDiskLoc)
            cursor = cursor._addSpecial("$showDiskLoc", true)
        if ($hint)
            cursor = cursor._addSpecial("$hint", $hint)
    
        if (sort)
            cursor = cursor.sort(sort)
        if (skip>-1)
            cursor = cursor.skip(skip)
        if (limit>-1)
            cursor = cursor.limit(limit)
    
        while(cursor.hasNext)
            append(cursor.next())
    }
    
    onCollectionChanged: collection.refreshed.connect(update)
    

    }
    @

    But I'm getting this error:
    @file:///home/manuel/lib/QtMongo/QtMongo/MongoQuery.qml:50:5: ListModel: undefined property 'onCollectionChanged'
    onCollectionChanged: collection.refreshed.connect(update)@

    Is there anything I did not get?



  • I don't think you will automatically get signal. You should define them and fire signal at appropriate places ( when you think property has changed ). In QML, everytime a property is changed, they must have been firing a signal with "propertyChanged" name. May be slot is automatically defined. I mean "onPropertyChanged" is automatically defined for you by the framework.



  • bq. I don’t think you will automatically get signal.

    Well, have a look at the onXChanged example in the documentation I posted^^.
    As far as I understand this, this slot will automatically be called.



  • What you said is true..

    @http://doc.qt.nokia.com/4.7/qml-extending-types.html
    Property change signals

    Adding a property to an item automatically adds a value changed signal handler to the item. To connect to this signal, use a signal handler named with the on<Property>Changed syntax, using upper case for the first letter of the property name.@

    Its interesting. I suppose that MongoCollection is userdefined type. How can QML know when to raise a signal when you change some internal state of you type. When do you want qml to raise a signal for you???



  • Yes, it is a user defined QML type (not using C++ magic).

    It should be raised after a call like this:
    @mongoQuery.collection = myCollection@



  • Hi,

    This might be because ListModel uses a custom parser -- does the following work for you?

    @
    Item {
    property MongoCollection collection
    onCollectionChanged: console.log("changed")
    }
    @

    If so, I'd suggest logging a bug (something along the lines of "on<Property>Changed syntax doesn't work inside ListModel"), and seeing if you work around this in the mean time (maybe using a wrapper object and placing the property there if that is applicable in your case?)

    Regards,
    Michael



  • Hi Michael,

    thanks, it works fine with the 'Item', so I created a "bug report":http://bugreports.qt.nokia.com/browse/QTBUG-19763


Log in to reply
 

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