I main.qmlに次のQMLのコードがあります:クロックまたはゲージをシミュレートし、私もに接続され、C++の機能を持っているとしてQMLの回転角度プロパティを設定する方法を変更する変数
Window {
visible: true
width: 640
height: 480
onBeforeRendering: Work.start()
Connections{
target: Work
onResult: res.text = r
}
Text{
id: res
}
Rectangle{
id: rect
anchors.centerIn: parent
height: 300
width: 300
color: "lightblue"
radius: 300
Rectangle{
id:needle
color: "black"
height: 150
width: 2
x: 150
y: 150
transform: Rotation { origin.x: 0; origin.y: 0; axis { x: 0; y:0 ; z: 1 } angle: 30}
smooth: true;
}
}
}
をText {id:res}に変化する値を表示する "onResult"イベント。すべてがうまくいく。
私がこれに追加したいのは、Rotation angleプロパティーをConnections内の "r"結果に回転角度としてフックする方法です。
私は次のように追加すると、それを動作させるだろうと思ったが、私は運がなかった:私はすべてのエラーか何かが届かないので、私は、私は正しい道を、物事をフックいないよ知って
Connections{
target: Work
onResult: needle.angle = r
}
Rectangle{
property double angle: 0
id:needle
color: "black"
height: 150
width: 2
x: 150
y: 150
transform: Rotation { origin.x: 0; origin.y: 0; axis { x: 0; y:0 ; z: 1 } angle: angle }
smooth: true;
}
を。私はどんな助けにも感謝します、ありがとう!
「ワーク」とは何ですか?どの時点でそれは機能しませんか? – derM
"r"値を提供する信号を持つ登録されたクラスです。したがって、 "engine.rootContext() - > setContextProperty(" Work "、&cw);" –
問題はおそらくangle:angleによると考えられます。角度を試す:needle.angle –