Question

import QtQuick 1.0

Rectangle 
{
   id: rect
   width: 100; height: 100
   color: "red"
   property int hh:0

   Text
   {
     text: hh
   }

   MouseArea 
   {
    anchors.fill: parent

    onPressed:
    {
        animation.start()
        console.log(hh)
    }

    NumberAnimation 
    { 
        id: animation
        target: rect
        property: "hh"
        to: 50; 
        duration: 1000 
    }
  }
}

Nothing gets printed on the console. I know that the hh is getting changed but I want to see its printed value on the console at the same time. What to do about it?

Was it helpful?

Solution

Your value hh is correclty displayed on console in fact, but only one time, when mouse is pressed. So at the first time it will print 0 (as the animation has not change the value and is asynchron), and 50 all the other times.

If you want to print all the intermediate values of hh, just handle change signal on this property :

import QtQuick 1.0

Rectangle 
{
   id: rect
   width: 100; height: 100
   color: "red"
   property int hh:0

   Text
   {
     text: hh
   }

   MouseArea 
   {
    anchors.fill: parent

    onPressed:
    {
        animation.start()
        console.log(hh)
    }

    NumberAnimation 
    { 
        id: animation
        target: rect
        property: "hh"
        to: 50; 
        duration: 1000 
    }
  }

  onHhChanged: console.log(hh)
}

For completeness, note the camelize syntax convention used for defining automatically a signal handle on a custom property.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top