QMLスコープに関するドキュメントを読みました。
このドキュメントでは、次のことが許可されています (コンポーネント インスタンス階層の下で、上記のドキュメントの 2 番目の例):
マイ ステートマシン ( BaseStateMachine.qml
):
import QtQuick 2.5
import QtQml.StateMachine 1.0 as DSM
DSM.StateMachine {
property string someProperty
running: true
}
私の州 ( BaseState.qml
):
import QtQuick 2.5
import QtQml.StateMachine 1.0 as DSM
DSM.State {
onEntered: someProperty = "some value"
}
私のメイン ( main.qml
):
import QtQuick 2.5
import QtQml.StateMachine 1.0 as DSM
ApplicationWindow {
// ...
BaseStateMachine {
initialState: state
BaseState {
id: state
}
}
}
しかし、次のエラーが表示されます。
qrc:/qml/BaseState.qml:4: ReferenceError: someProperty is not defined
私は何か誤解していますか?また、qml の StateMachine に関するドキュメントも読みましたが、StateMachine と State 内でのスコープの例外は見つかりませんでした。
アップデート:
このようにIDを追加するとBaseStateMachine.qml
:
import QtQuick 2.5
import QtQml.StateMachine 1.0 as DSM
DSM.StateMachine {
id: _baseStateMachine
property string someProperty
running: true
}
someProperty
その後、QtCreator はinを認識するようになりBaseState.qml
ます。「認識される」の下で、つまり、その中のプロパティを ctrl/command+click すると、 がBaseState.qml
表示されBaseStateMachine.qml
ます。QtCreatorから ID を削除するとすぐにBaseStateMachine.qml
、もう見つかりsomeProperty
ません。