문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top