我有两个QML文件。在First.qml中,我可以使Second.qml可见。在Second.qml中,我有selectedParts变量。我希望将selectedParts设置为始终为1值,当使Second.qml可见时。这只在我第一次加载Second.qml时才起作用。如果我使selectedParts Second.qml不可见,然后使其可见,则2值。在我单击selectedParts时,是否总是将myImage变量公开并设置其值?
First.qml
Item {
Image {
id: myImage
MouseArea{
anchors.fill: parent
onClicked: {
second.visible = true
...
}
}
}
}Second.qml
Item {
property int selectedParts: 1
Image {
id: myImage2
MouseArea{
anchors.fill: parent
onClicked: {
selectedParts = 2
...
}
}
}
}发布于 2015-07-01 16:42:39
我通过在Second.qml文件中添加back按钮来解决我的问题。在这个按钮中,我放置了语句selectedParts = 1。
发布于 2015-06-21 03:21:09
QML公共变量?查找MessageBoard in 从C++定义QML类型。我们正在采用这种办法。您所需要的只是创建C++ MessageBoard对象,将一些数据放入其中,并通过提供给每个QML根对象的QML上下文引用它:
m_quickView.engine()->rootContext()->setContextProperty("myMsgBoard", MyQmlMsgBoard::instance());在QML中:
Rectangle {
id: topRect
scale: myMsgBoard.scale // or anywhere in QML
// ....
}当然,“留言板”C++对象向QML公开如下所示:
Q_PROPERTY(qreal scale READ scale CONSTANT);https://stackoverflow.com/questions/30954657
复制相似问题