Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold
Accepted Solution

How to Prevent Pushing of a QML Page When Already in That Page

Hi,

 

In main.qml I have the following menu action item that displays SettingsPage.qml. 


main.qml:

 

NavigationPane {
    id: nav

    ...

    Menu.definition: MenuDefinition {
        actions: [

            ...

            ActionItem {
                title: "Settings"          
                onTriggered: {
                    console.log("entering settings page");

                    var settingsPage = settingspagedef.createObject();
                    Qt.nav.push(settingsPage);
                }
            },

            ...

            ] // end of actions list
        
     } // end of MenuDefinition

....

Page {

....

}

 

And, the SettingsPage.qml is a QML file containing only the Page element (not in a NavigationPane). So, in the Settings page, another settings page is pushed on top of the current settings page when clicked on the "Settings" action item. How can I prevent pushing of another SettingsPage.qml when there's already a settings page? Thanks in advance.

 

 

Developer
Posts: 6,145
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How to Prevent Pushing of a QML Page When Already in That Page

There are a few ways of doing it;

 

1) Set a boolean flag in the action

2) Check the stack for a duplicate page and refuse another

3) Give the page a name and use the onTopChanged() signal to check if it's the first

4) remove/disable that menu option/action

 

Having said all that I don't understand why you are getting a double page there should be no way to go back to where your settings page is called from while still in the settings page.

 

Perhaps you aren't destroying the page as you navigate back and forth?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold

Re: How to Prevent Pushing of a QML Page When Already in That Page

I am getting a double page because in Settings page, clicking on settings action item on top menu pushes another instance of the Settings page. The page is getting destroyed when navigating back, but in this case I am not navigating back. 

 

I will try your suggestions, thanks.

Developer
Posts: 6,145
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How to Prevent Pushing of a QML Page When Already in That Page

Ok understood, if by top menu you mean the Application menu then there is another option; within your settings page you can disable it completely using something like;

 

onCreationCompleted: {

    Application.menuEnabled = false;

}


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold

Re: How to Prevent Pushing of a QML Page When Already in That Page

Yes, I mean the Application menu.

 

Your code disables the whole menu. What if I only don't want the Settings menu option? I guess I have to disable the action item in the main.qml. Is there another way to reach the action item in other QML (main.qml) other than putting it into Qt object?

 

onCreationCompleted: {
     Qt.nav = nav;
     Qt.catList = categoriesList;

}

 

 

 

Developer
Posts: 6,145
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How to Prevent Pushing of a QML Page When Already in That Page

[ Edited ]

You can access by normal aliasing of the enabled attribute,

 

Page {
    property alias enable_utils: utilities.enable
    id: navigationPane
    objectName: "navPane"

    Menu.definition: MenuDefinition {
         actions: [
             ActionItem {
                id: utilities
                title: qsTr("Utilities")
                imageSource: "asset:///images/actions/tools.png"
                enabled: false
                onTriggered: {                       var page = utilitiesPageDefinition.createObject();                       navigationPane.push(page);                       // Could disable here                 }          }
     [ ... ]
}

 

Page {     navigationPane.enable_utils = false; }

 

Alternatively you can use signals and slots or just disable it within the onTriggered slot of the main page.


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 932
Registered: ‎03-20-2013
My Device: Red LE Developer Z10

Re: How to Prevent Pushing of a QML Page When Already in That Page

[ Edited ]

I prefer to remove the Settngs button completely rather than disable it when I don't want my user to have access to it. My app declares the application menu like this:

 

MenuDefinition {
id: appMenu settingsAction: _settingsAction helpAction: _helpAction attachedObjects: [ SettingsActionItem { id: _settingsAction onTriggered: { } }, HelpActionItem { id: _helpAction onTriggered: { } } ] actions: [ ] function restoreSettingsAction() { settingsAction = _settingsAction; } function restoreHelpAction() { helpAction = _helpAction; } }

Now from QML you can do this:

 

// ---Remove the application menu Settings button
appMenu.settingsAction = null;

// ---Restore the application menu Settings button
appMenu.restoreSettingsAction();

... and you can do the same with the help button if you like. Note that if you have any other buttons on your application menu they will probably move around on the menu if you remove/restore the Settings or Help buttons.

 


burakk wrote:

Yes, I mean the Application menu.

 

Your code disables the whole menu. What if I only don't want the Settings menu option? I guess I have to disable the action item in the main.qml. Is there another way to reach the action item in other QML (main.qml) other than putting it into Qt object?

 

onCreationCompleted: {
     Qt.nav = nav;
     Qt.catList = categoriesList;

}

 

 

 






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.
Developer
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold

Re: How to Prevent Pushing of a QML Page When Already in That Page

[ Edited ]

@greenemr

 

... and where to call 

appMenu.restoreSettingsAction(); ?

 

It did not work in onCreationCompleted() of the main.qml, also in onPopTransitionEnded()

Developer
Posts: 149
Registered: ‎04-23-2011
My Device: BlackBerry 9700 Bold

Re: How to Prevent Pushing of a QML Page When Already in That Page

Well, just added:

 

paneProperties: NavigationPaneProperties {
        backButton: ActionItem {
            onTriggered: { 
            	appMenu.restoreSettingsAction();
                nav.pop(); 
            }
        }
    }

 

 

to SettingsPage.qml, and it works. Thank you.

Developer
Posts: 6,145
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: How to Prevent Pushing of a QML Page When Already in That Page

@greenmr have you tested your code to make sure it doesn't leak or crash when you pop a page having effectively set a pointer to null but left the object in memory are you sure that it gets cleaned up on app shutdown or page pop?


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.