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
Dredvard
Posts: 157
Registered: ‎01-27-2012
My Carrier: Rogers
Accepted Solution

Does MenuDefinition not work in QML yet?

I added the following code:

      Page {
        Menu.definition: MenuDefinition {
            settingsAction: SettingsActionItem {
                onTriggered: {
                }
            }
            actions: [
                ActionItem {
                    title: "testingout"
                    onTriggered: {
                    }
                    imageSource: "images/xdarkimage.png"
                }
            ]
        }
        Container {
..

 Code works fine without the menu and doesn't work with it.  Gives me the following errorf:

 

Non-existent attached object
            Menu.definition: MenuDefinition {
            ^)

 

Is there something I'm missing?

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Developer
peter9477
Posts: 6,448
Registered: ‎12-08-2010
My Carrier: none

Re: Does MenuDefinition not work in QML yet?

In what way does it not work? If you mean that when you launch the app, you get a black screen, or some similar form of "doesn't work", then just check your log output. You should see an error message that will probably point you to the exact line of the .qml and describe the nature of the problem.

Search for "slog2info" in the forum if you have no idea how to do that...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
Dredvard
Posts: 157
Registered: ‎01-27-2012
My Carrier: Rogers

Re: Does MenuDefinition not work in QML yet?

This is the error message I get in my console (copy/pasted here)

 

.... Non-existent attached object
            Menu.definition: MenuDefinition {
            ^)

 

I use

 

    qInstallMsgHandler(myMessageOutput);

 

so I don't have to use slo2info.

 

It points me to Menu.definition as seen above.  I think its a bug.  Checked the code in the api pages and the help in the IDE and both say that is the way to do it.  Try copying the above code into a page and see if it works. 

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Developer
greenback
Posts: 490
Registered: ‎10-17-2010

Re: Does MenuDefinition not work in QML yet?

Add the Menu to the root of your qml page

 

Use this code:

 

 Menu.definition: MenuDefinition {
        // Add a Help action
        helpAction: HelpActionItem {
            // do something there
            onTriggered: {
                
            }
        }

        // Add a Settings action
        settingsAction: SettingsActionItem {
            onTriggered: {
                //do something here
                //like show the settings screen
            }
        }
    }

 
Reference:
 http://cascadescode.tumblr.com/post/32618415391/make-a-swipe-down-blackberry-10-cascades-menu

Please use plain text.
Developer
peter9477
Posts: 6,448
Registered: ‎12-08-2010
My Carrier: none

Re: Does MenuDefinition not work in QML yet?

[ Edited ]

Dredvard, what's the rest of the structure of the UI?

It does look like it needs to be in the root, or at least it doesn't seem to work if you have it in a Page which is in a Tab of a TabbedPane.

That said, putting it in a Page within a Tab does not result in the error message you showed. Nor does have a local file called Menu.qml or MenuDefinition.qml, which was one of my guesses.  (Edit: Dredvard reports in a later post that he did have a Menu.qml which was causing the problem, so for whatever reason it's not necessarily the case that having such a file will give that error message, but it's probably the case that getting that error message should tell you to look carefully for a Menu.qml file and rename it.)

It does work, so you need to shrink the code down to the simplest thing that reproduces the problem. At that point, you'll likely have found your own solution and can post it here. I just put your code into a simple Page and it works perfectly well...


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
Dredvard
Posts: 157
Registered: ‎01-27-2012
My Carrier: Rogers

Re: Does MenuDefinition not work in QML yet?

[ Edited ]

Well as far as I can tell I've identified the error is outside of my code- and in the xml files or .pro

 

I copied the menudef that worked in greenbacks code into mine and got the same error.

 

I started a new project from scratch copying all the code and assets in... and got the same error.

 

I then started a new project using a NavigatorPane template and copied the code in and it worked.   I then copied my entire source code into the NavigatorPane template and it worked.

 

I then copied the template base that worked in to my original project and called it from the main... and got the same error!

 

This is very perplexing.  At this point I guess my best option is to start adding permission into the new NavigatorPane template and hopefully it keeps working.  I have no idea what is the cause.

 

Why in some projects does it tell you that fprintf is out of scope in main, (had to include #include <stdio.h>).  The two projects that have the error, I don't have to do that include but the one that needs it works.  Tried looking at the compiler options and couldn't see anythign different.

 

Edit:  Disregard the above.  Just copied the NavPane template qml into the original and the menu pulled down.     I'll just keep on deleting and hopefully I figure it out.

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Developer
Dredvard
Posts: 157
Registered: ‎01-27-2012
My Carrier: Rogers

Re: Does MenuDefinition not work in QML yet?

Ok, the issue is that you can't attach Objects if you use that menu Definition code.  How do you attachObjects and use menu defnitions?

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Developer
peter9477
Posts: 6,448
Registered: ‎12-08-2010
My Carrier: none

Re: Does MenuDefinition not work in QML yet?

Not sure what you mean, but I have an app here that has (in a TabbedPane) a Menu.definition just like yours, followed immediately by an attachedObjects: [] list of stuff... You shouldn't be seeing an issue using both.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Developer
Dredvard
Posts: 157
Registered: ‎01-27-2012
My Carrier: Rogers

Re: Does MenuDefinition not work in QML yet?

Its actions.  Menus can't be used with actionItems.

 

Wow.  That took a while.  Try this code:

 

NavigationPane {
    id: navPaneid
        Menu.definition: MenuDefinition {
            // Add a Help action
            helpAction: HelpActionItem {
                // do something there
                onTriggered: {
                }
            }
    
            // Add a Settings action
            settingsAction: SettingsActionItem {
                onTriggered: {
                    //do something here
                    //like show the settings screen
                }
            }
        }

    Page {
        id: pageid
        Container {
          Label{
              text:"testing"
          }
        }
       actions: [
            ActionItem {
                id: playid
                title: "Play"
                imageSource: "images/playimage.png"
                objectName: "Play"
            }
        ]
    }
}

 

---
If you find my post helpful please "like" it and "accept as a solution"
Please use plain text.
Developer
peter9477
Posts: 6,448
Registered: ‎12-08-2010
My Carrier: none

Re: Does MenuDefinition not work in QML yet?

Dredvard, that's also not true. I'm using an ActionItem in my menu with no problems.

Also, you yourself noted earlier "I then started a new project using a NavigatorPane template and copied the code in and it worked." If it worked then, clearly the answer can't be as simple as "menus can't be used with ActionItems".

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.