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
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel
Accepted Solution

How to create Action Item dynamically?

Hi, I want to create item dynamically.

Before I want to create it using qml, but seems not possible

 

http://supportforums.blackberry.com/t5/Cascades-Development/How-to-create-Action-Item-of-page-dynami...

 

So maybe better use C++ to create it dynamically,

I'm already try it but still fail

 

So I have a custom control qml (a Navigation Pane)

name List.qml

 

the structure is like this :

 

NavigationPane {

Page {

   objectName: myPage

   Container {

   ....

}

}

}

 

How to add action item to that .qml ?

 

I'm already try this, but fail

On C++:

 

QDeclarativeEngine engine;

QDeclarativeComponent component(&engine,QUrl::fromLocalFile("List.qml"));

QObject *object = component.create();

 

Page *myPage = object->findChild<Page*>("myPage");  // maybe on this I'm wrong implement it ?? -> not found?

ActionItem* action1 = ActionItem::create().title("First action");

myPage->addAction(action1, ActionBarPlacement::smileysurprised:nBar);

 

delete object;

 

 

How to create this Action Item dynamically?

Please help,

Thanks

 

Please use plain text.
Contributor
chriske86
Posts: 43
Registered: ‎01-05-2013
My Device: Dev Alpha
My Carrier: Telenor Hungary

Re: How to create Action Item dynamically?

Hi,

 

in QML, the object name must be between " " marks.

 

So your Page's object name will be:

 

objectName: "myPage"

 You can reach any QML object from cpp like this:

 

//this snippet is from YourProjectName.cpp

// create scene document from main.qml asset
// set parent to created document to ensure it exists for the whole
// application lifetime
    
QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);

    // create root object for the UI
    AbstractPane *root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene
    app->setScene(root);

//and here comes the findChild method
Page* qmlPage = root->findChild<Page*>("myPage");

 After this, You can create any QML object from C++ side, like your own code:

 

ActionItem* action1 = ActionItem::create().title("First action");
myPage->addAction(action1, ActionBarPlacement:nBar);

 Don't need to create a QObejct, or declarative stuff.

--------------------------------------------------------------
If my post was helpful or it was the solution for Your problem, please don't forget to give me a like, and mark my post as a solution. Thanks!
Please use plain text.
Developer
Kaz32
Posts: 236
Registered: ‎11-24-2012
My Device: Blackberry 10 Dev Alpha
My Carrier: Telkomsel

Re: How to create Action Item dynamically?

Hi I try your suggestion, and it works

I forgot to add * *marks on object name

 

And I'm wrong on this:

I use VideosPage.qml on createqmlDocument

QmlDocument *qml = QmlDocument::create("asset:///VideosPage.qml").parent(this);

 

actually using main.qml will work no need use that custom.qml, as long custom.qml use at main.qml I think

 

 

Thanks for your reply

 

Please use plain text.