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: 1,159
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

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

If you look closely you'll notice that I didn't do this:

 

MenuDefinition {
    id: appMenu
    settingsAction: SettingsActionItem {
        id: _settingsAction
            onTriggered: {
            }
        }
    function restoreSettingsAction() {
        settingsAction = _settingsAction;
    }
}

... since changing settingsAction to null would have orphaned the action, requiring a new SettingsAction to be created to restore the button. Even doing it this way though would not create a leak since every SettingsAction created would become, and remain, a child of appMenu as soon as it was assigned to settingsAction (check documentation for MenuDefinition::setSettingAction() ). You might get a lot of SettingsActions floating around, but they would all be cleaned up when the MenuDefinition is destroyed.

 

By declaring the SettingsAction as an attached object though, all my original code example is doing is messing with the settingsAction pointer, not the action. settingsAction = null translates to C++ code setSettingsAction( NULL ) which as I said, doesn't break the parent/child relationship of the old SettingsAction assigned to settingsAction. The attached SettingsAction is created only once, along with the MenuDefinition, and is destroyed only once, when appMenu is destroyed. Even though settingsAction is changed to null, appMenu is still the parent of _settingsAction.

 

There are no leaks since the ownership of _settingsAction is never changed after its original assignment via settingsAction: _settingsAction.

 


BBSJdev wrote:

@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?






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 1,159
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

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

I would need to see how you structure your NavigationPane, since it works perfectly in my app in onPopTransitionEnded.

 

I can't see why you'd want to call it in onCreationCompleted since the Settings button will already be visible then. It is only hidden when you explicitly call appMenu.settingsAction = null when you push a page. Here is a simplified example:

 

NavigationPane {
    id: frontPage
    Menu.definition: MenuDefinition {
        id: appMenu
        settingsAction: _settingsAction
        attachedObjects: [
            SettingsActionItem {
                id: _settingsAction
                onTriggered: {
                    appMenu.settingsAction = null;
                    frontPage.push( mySettingsPage );
                }
            }
        ]
        function restoreSettingsAction() {
            settingsAction = _settingsAction;
        }
    }
    attachedObjects: [
        MySettingsPage {
            id: mySettingsPage
            objectName: "mySettingsPage"
        }
    ]
    onPopTransitionEnded: {
        if ( page.objectName = "mySettingsPage" ) {
            appMenu.restoreSettingsAction();        
        }
    }
}

 


burakk wrote:

@greenmr

 

... and where to call 

appMenu.restoreSettingsAction(); ?

 

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






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.