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. On<property name>Changed: undefined property
Forum Updated to NodeBB v4.3 + New Features

On<property name>Changed: undefined property

Scheduled Pinned Locked Moved QML and Qt Quick
7 Posts 3 Posters 7.6k Views 1 Watching
  • 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 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        manuelsch
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thisisbhaskar
          wrote on last edited by
          #4

          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???

          1 Reply Last reply
          0
          • M Offline
            M Offline
            manuelsch
            wrote on last edited by
            #5

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

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

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbrasser
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • M Offline
                M Offline
                manuelsch
                wrote on last edited by
                #7

                Hi Michael,

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

                1 Reply Last reply
                0

                • Login

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