June 4, 2011

manuelsch manuelsch
Lab Rat
24 posts

on<property name>Changed: undefined property

 

Hi,

corresponding to the documentation [doc.qt.nokia.com], on can catch changes of properties using the <property_name>Changed signal

I tried to implement this for the collection property of this object:

  1. import QtQuick 1.1
  2. import "lib/json/json2.js" as Json
  3.  
  4. ListModel {
  5.     id: mongoQuery
  6.  
  7.     property MongoCollection collection
  8.     property variant query
  9.     property variant sort
  10.     property int limit: -1
  11.     property int skip: 0
  12.     property bool snapshot: false
  13.     property bool $returnKey: false
  14.     property int $maxScan: -1
  15.     property variant $min
  16.     property variant $max
  17.     property bool $showDiskLoc: false
  18.     property variant $hin-t
  19.  
  20.     function update() {
  21.         clear()
  22.  
  23.         var cursor = collection.find(query)
  24.         console.log( Json.JSON.stringify(query) )
  25.  
  26.         if ($returnKey)
  27.             cursor = cursor._addSpecial("$returnKey", $returnKey)
  28.         if (snapshot)
  29.             cursor = cursor.snapshot()
  30.         if ($min)
  31.             cursor = cursor._addSpecial("$min", $min)
  32.         if ($max)
  33.             cursor = cursor._addSpecial("$max", $max)
  34.         if ($showDiskLoc)
  35.             cursor = cursor._addSpecial("$showDiskLoc", true)
  36.         if ($hint)
  37.             cursor = cursor._addSpecial("$hint", $hint)
  38.  
  39.         if (sort)
  40.             cursor = cursor.sort(sort)
  41.         if (skip>-1)
  42.             cursor = cursor.skip(skip)
  43.         if (limit>-1)
  44.             cursor = cursor.limit(limit)
  45.  
  46.         while(cursor.hasNext)
  47.             append(cursor.next())
  48.     }
  49.  
  50.     onCollectionChanged: collection.refreshed.connect(update)
  51. }

But I’m getting this error:

  1. file:///home/manuel/lib/QtMongo/QtMongo/MongoQuery.qml:50:5: ListModel: undefined property 'onCollectionChanged'
  2.          onCollectionChanged: collection.refreshed.connect(update)

Is there anything I did not get?

6 replies

June 5, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
383 posts

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.

June 5, 2011

manuelsch manuelsch
Lab Rat
24 posts

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.

June 5, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
383 posts

What you said is true..

  1. http://doc.qt.nokia.com/4.7/qml-extending-types.html
  2. *Property change signals*
  3.  
  4. 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???

June 6, 2011

manuelsch manuelsch
Lab Rat
24 posts

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

It should be raised after a call like this:

  1. mongoQuery.collection = myCollection

June 7, 2011

mbrasser mbrasser
Lab Rat
452 posts

Hi,

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

  1. Item {
  2.     property MongoCollection collection
  3.     onCollectionChanged: console.log("changed")
  4. }

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

June 7, 2011

manuelsch manuelsch
Lab Rat
24 posts

Hi Michael,

thanks, it works fine with the ‘Item’, so I created a bug report [bugreports.qt.nokia.com]

 
  ‹‹ TileMap with qml element Image      [SOLVED] A listmodel Index problem, thanks for your help! ››

You must log in to post a reply. Not a member yet? Register here!