1

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.

Francis F
  • 3,157
  • 3
  • 41
  • 79

1 Answers1

3

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"
QtRoS
  • 1,149
  • 1
  • 16
  • 23
  • I can access the reloadView() anywhere from homepage.qml but I need to access it from main.qml. Or is there any other way to directly notify homepage that profilepage has been popped. – Francis F Dec 23 '14 at 08:45
  • Your problem is that you can't access homepage itself, not it's function "reloadView()". Take a look at my example - special property "myHomePage" is used to access your child page. Try it. – QtRoS Dec 23 '14 at 08:55
  • ok, but my question is from where would I call it? Suppose I'm in profilepage and clicking on back button will take me to homepage, and I need to call reload when it lands back on homepage. Is there any other methods like onCreationComplete that will be called while popping back. Note that my navigation pane is in main.qml so I can access onPopTransitionEnded on main page only or is there any other way to access onPopTransitionEnded on homepage? – Francis F Dec 23 '14 at 09:02
  • My actual problem is that I have a listview in homepage, whose data can be changed in profilepage and after the data is changed I need to refresh my listview after coming back from profilepage. – Francis F Dec 23 '14 at 09:06
  • 1
    Answer is - anywhere. To call some function in QML you need object. If you have a reference to an object you can call it's functions and access it's properties. You can write code as you wish and call anything from any place, but all you need is reference to an object. My answer solves you problem with this reference. I will update anwser soon, take a look on it again. – QtRoS Dec 23 '14 at 09:09