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
}