0

I have 4 pages in my application that goes in order main.qml, login.qml,home.qml and profile.qml. home.qml has a listview that list some data which can be modified in profile.qml. So whenever I come back from profile.qml to home.qml I need to refresh my listview. My main.qml has the navigation pane so I have written the code to refresh the listview on main.qml and it does calls the reloadview function in the home.qml. My problem is if a user logs in for first time then navigation stack has all pages [main.qml, login.qml,home.qml,profile.qml] and when I pop from profile.qml the reload function gets called but the listview refresh doesnt happen on home.qml. But if an already logged in user logs in then at that time navigation stack has the pages [main.qml,home.qml,profile.qml] and when I pop from profile.qml the reload function gets called and the listview also gets refreshed properly. So I guess there is some problem refreshing listview from main.qml if login.qml exist in stack but works fine if its not there. Any idea how should I fix this? Or is it possible to remove login.qml from stack after I have pushed from login.qml to home.qml? I tried popping login.qml and then pushing and it worked but popping causes the main.qml to show until its pushed back to home.qml. Any advice is greatly appreciated.

Below are the sample structures of my qmls

main.qml

NavigationPane {
    id: nav
    peekEnabled: false
    onPopTransitionEnded: {
        if(page.objectName=="newProfilePage")
        {
            if(!myHomePage)
            {
                myHomePage=homePageDefenition.createObject();
            }
            myHomePage.reloadView();
        }
        page.destroy();
    } 
    Page {
        id: mainPage

        Container {
            //some code
        }
        onCreationCompleted: {
            //Some code and then push to homepage
            nav.push(homePageDefenition.createObject());
        }
    }
}

loginpage.qml

Page {

    id: loginPage
    objectName: "loginPage"
    Container {
        //some code to validate login and push to homepage
        var homePage=homePageDefinition.createObject();
        nav.push(homePage);
    }
}

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: {              
                nav.pop();
            }
        }
    }
}

EDIT

homepage.qml (Modified)

This is my homepage structure

Page {

    //some code
    function reloadView()
    {
        homePageScroll.getMyContacts(_settings.getArrayFor("contactList", null));
    }

    Container {
        layout: DockLayout {
        }
        ScrollView {
            id: homePageScroll

            Container {
                layout: DockLayout {
                }
                ListView { 
                    //somecode
                }
            }

            function getMyContacts(contacts)
            {
                //code as shown below
            } 
        }
        attachedObjects:[
            GroupDataModel {
                id: contactsData
                sortingKeys: [ "last" ]
                grouping: ItemGrouping.None
            }
        ]
    }
    ImageButton {
        id: nextButton
        defaultImageSource: "asset:///Images/next_button.png"
        pressedImageSource: "asset:///Images/next_button_pressed.png"
        horizontalAlignment: HorizontalAlignment.Right
        verticalAlignment: VerticalAlignment.Bottom
        onClicked: {
            myMenuScreen = profilePageDefinition.createObject();
            nav.push(myMenuScreen);
        }
    }

//Get my contacts function called in reloadview

function getMyContacts(contacts) 
{
    console.log("Contact List:" + contacts); //Contains list of updated contacts and prints correctly
    contactsData.clear();
    var blockedContacts = _settings.getArrayFor("blockList", null);

    console.log("Blocked Contact List:" + blockedContacts);

    var addContact = "true";
    for (var cntNames in contacts) {
        for (var blockedNames in blockedContacts) {
            if (contacts[cntNames].toString() == blockedContacts[blockedNames].toString()) {
                addContact = "false";
                break;
            } else {
                addContact = "true";
            }
        }
        if (addContact == "true") {
            console.log("Inserting:"+contacts[cntNames].toString());
            contactsData.insert({
                name: contacts[cntNames].toString(),
                last: contactsData.size(),
                colors:getMyListItemColor(contactsData.size())
            })
        }
    }

    var newContacts = new Array();
    for (var i = 0; i < contactsData.size(); i ++) {
        if (contactsData.data([ i ]).name != '+' ) {
            newContacts.push(contactsData.data([ i ]).name);
        }
    }
    _settings.saveArray("contactList", newContacts); //Save the array of contacts in qsettings

    console.log("UPdated Contact List:" + newContacts + "        Size:"+contactsData.size().toString()); // This prints correctly

}
sam
  • 2,780
  • 1
  • 17
  • 30
Francis F
  • 3,157
  • 3
  • 41
  • 79
  • Wait, you have ListView in main.qml and homepage.qml? And why do you try to recreate homepage when you could just store homePageDefenition when you first make it? – Bojan Kogoj Dec 24 '14 at 09:42
  • I have a listview in main.qml to show the login options they are fixed, homepage listview list all the other data. I'm trying to refresh the homepage listview. Where am I recreating homepage? – Francis F Dec 24 '14 at 11:15
  • Ok I looked again, you're not recreating it. It's just a mess to understand. Why don't you put this in profilepage.qml: `nav.menuScreenPage.reloadView()` It should call the function. Other than that I suggest you use `property variant homePage` inside NavigationPane and store object of homepPageDefinition there – Bojan Kogoj Dec 24 '14 at 13:14
  • I did that, my problem is not that the function is not getting called, it does get called and log prints correct listview items but the listview doesnt get updated. – Francis F Dec 24 '14 at 13:41
  • But if the function gets called and prints correct items, then it has to be a problem with reloadView(). Show us that – Bojan Kogoj Dec 24 '14 at 15:01
  • Not sure why it doesnt reload, currently I popped login.qml from stack while login and it works. But no refresh action occurs when its there. I have updated my code for your review. – Francis F Dec 26 '14 at 16:44

0 Answers0