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
behrk2
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified
Accepted Solution

Dynamically Adding a Tab in C++ or QML (with existing QML as the tab content)

Hello,

 

I'm trying to dynamically add a tab into an existing TabbedPane.  I am able to do this via C++ with:

 

Page* page = Page::create();
Tab* tab = Tab::create().title("title").description("description");
tab->setContent(page);
app->tabbedPane->add(tab);

...but I don't want to add an empty Page.  I want to instantiate an existing QML document into the tab as the content, in the same way that I define the first tab in QML:

 

Tab {
     id: defaultTab
     objectName: "defaultTab"
     title: "title"
     CMLocationView {
     }
}

 Can this be done in C++?  In QML?  In both?

 

Thanks!

Developer
congdanhqx
Posts: 115
Registered: ‎10-22-2012
My Device: Developer

Re: Dynamically Adding a Tab in C++ or QML (with existing QML as the tab content)

In C++

QmlDocument *qml = QmlDocument::create("asset:///UI.qml").parent(this);
// create root object for the UI
// you can change AbstractPane to the type you declared in QML such as Page, NavigationPane etc AbstractPane *root = qml->createRootObject<AbstractPane>(); Tab* tab = Tab::create().title("title").description("description"); tab->setContent(root); app->tabbedPane->add(tab);

 



Like my answer if it's helpful. Mark as answer if it help you solve the problem.
Developer
congdanhqx
Posts: 115
Registered: ‎10-22-2012
My Device: Developer

Re: Dynamically Adding a Tab in C++ or QML (with existing QML as the tab content)

In QML

TabbedPane {
    id: tabbedPane
    ...
    attachedObjects: [
        ComponentDefinition {
            id: pageDefinition
            source: "asset:///UI.qml"
        }
    ]
    function newTab() {
        var c = "import bb.cascades 1.0; Tab{}";
        var tab = Qt.createQmlObject(c,tabbedPane,"newTab")
        tab.content = pageDefinition.createObject(tab);
        tabbedPane.add(tab)
    }
}

 My small demo here

https://github.com/congdanhqx/BB10-Example/tree/master/tab-demo



Like my answer if it's helpful. Mark as answer if it help you solve the problem.
Developer
behrk2
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Dynamically Adding a Tab in C++ or QML (with existing QML as the tab content)

[ Edited ]

Thanks!  The C++ example works perfectly.  So does the QML example, except when I call the tabbedPane.newTab() function from a different QML document.  The function doesn't called in that case, and nothing happens.  Any ideas?

Developer
behrk2
Posts: 367
Registered: ‎11-25-2009
My Device: Not Specified

Re: Dynamically Adding a Tab in C++ or QML (with existing QML as the tab content)

Nevermind, the call to the function was never being called because I had a problem with my if statement.  

Contributor
srinivasaraoDharnasi
Posts: 25
Registered: ‎07-31-2013
My Device: Z10

Re: Dynamically Adding a Tab in C++ or QML (with existing QML as the tab content)

Hi,

 

  I have same problem, I applied this code but error was came at app->tabbedPane->add(tab).

 

error is:

 

error: 'class bb::cascades::Application' has no member named 'tabpane'

 

please let me know  where the "tabpane" was declared.