1
votes

In my application I have a main.qml which has a navigation pane that goes to homepage.qml and from there to profilepage.qml. When I come back from profilepage to homepage I need to trigger a function in home page. I noticed that whenever I pop back I get a call onPopTransitionEnded in the main page. Since homepage is pushed from main.qml there is no navigation pane on homepage and I cant access onPopTransitionEnded on homepage. Below are the sample structures of my 3 qml views.

main.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());
         }
      }
}

homepage.qml

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());
               }
            }

        }
     }

profilepage.qml

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();
               }
            }
          }
         }

So is there a way that I can access the function of homepage.qml from main.qml? Or is there any other function like onPopTransitionEnded which I can access on homepage.qml itself when I pop from profilepage? Please advice.

1

1 Answers

3
votes

Seems that you created unnamed object with this line:

homePageDefenition.createObject()

If you want to access it later, you should save it in some property, for ex.

property var myHomePage: null
...
myHomePage = homePageDefenition.createObject()
nav.push(myHomePage )
... 
myHomePage.reloadView();

Keep in mind that "menuScreenPage" is local name (id), it works only inside homepage.qml and nobody can access it beyond that file.

UPD

You can even use such code:

page.reloadView(); // Use local variable "page" instead of internal id "menuScreenPage"