在我的应用程序中,我有一个main.qml,它具有一个导航窗格,该导航窗格转到homepage.qml,然后从该窗格转到profilepage.qml。当我从个人资料页面返回首页时,我需要在首页中触发一个功能。我注意到,每当弹出时,我都会在主页上调用onPopTransitionEnded。由于主页是从main.qml推送的,因此主页上没有导航窗格,我无法访问主页上的onPopTransitionEnded。以下是我的3个qml视图的示例结构。
NavigationPane {
id: nav
peekEnabled: false
onPopTransitionEnded: {
console.log("POP PAGE from main");
if(page.objectName=="newProfilePage")
{
//I tried to access the function using the homepage id but didnt work
menuScreenPage.reloadView(); // This doesnt work, shows error unknown symbol menuScreenPage
}
page.destroy();
}
Page {
id: mainPage
Container {
//some code
}
onCreationCompleted: {
//Some code and then push to homepage
nav.push(homePageDefenition.createObject());
}
}
}
Page {
id: menuScreenPage
objectName: "menuScreenPage"
function reloadView() //This is the function that is needed to be called on page pop from profile page
{
//some code
}
Container {
//some code
Button { //a button to push to profile page
id:pushButton
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Bottom
onClicked: {
console.log("I was clicked!")
nav.push(profilePageDefinition.createObject());
}
}
}
}
Page {
id: newProfilePage
objectName: "newProfilePage"
Container {
//some code
Button { //a button to pop to home page
id:popButton
horizontalAlignment: HorizontalAlignment.Right
verticalAlignment: VerticalAlignment.Bottom
onClicked: {
console.log("I was clicked!")
nav.pop();
}
}
}
}
那么有没有办法可以从main.qml中访问homepage.qml的功能?或者是否还有其他功能,例如onPopTransitionEnded,当我从个人资料页面弹出时可以在homepage.qml本身上访问?请指教。
似乎您使用此行创建了未命名对象:
homePageDefenition.createObject()
如果要稍后访问,则应将其保存在某些属性中,例如。
property var myHomePage: null
...
myHomePage = homePageDefenition.createObject()
nav.push(myHomePage )
...
myHomePage.reloadView();
请记住,“ menuScreenPage”是本地名称(id),它仅在homepage.qml中有效,并且除该文件外没有人可以访问它。
UPD
您甚至可以使用以下代码:
page.reloadView(); // Use local variable "page" instead of internal id "menuScreenPage"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句