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
bskania
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer

dynamically add components in dialog not working.

Hello

I am developing one project.

In which main page is the Navigationpane, i.e I had loded in the application scene.

Now on the click of button the page is pushed to navigation pane.

 

2nd page qml 

  

Page {
    // page with a picture detail
    id: pgImage
    objectName: "pgImage"
    actions: [
        // create navigation panel actions here
        ActionItem {
            title: qsTr("Break")
            onTriggered: {
                imgView.imageSource = "asset:///images/picture1br.png"
            }
        }
    ]
    attachedObjects: [
        Custom_dialog {
            id:custom_dialog                       
        }
    ]
    paneProperties: NavigationPaneProperties {
        backButton: ActionItem {
            onTriggered: {
                // define what happens when back button is pressed here
                // in this case is closed the detail page
                navigationPane.pop()
            }
        }
    }
    Container {
        id: cnImage
        objectName: "cnImage"
        background: Color.Black
        Label {
            text: qsTr("Page 2")
            horizontalAlignment: HorizontalAlignment.Center
            textStyle {
                base: SystemDefaults.TextStyles.TitleText
                color: Color.Yellow
            }
        }
        ImageView {
            id: imgView
            imageSource: "asset:///images/picture1.png"
            horizontalAlignment: HorizontalAlignment.Center
        }
        Label {
            text: qsTr("Picture description")
            horizontalAlignment: HorizontalAlignment.Center
        }
        
        Button {
            text: "button"
            onClicked: {
                custom_dialog.open();
            }
        }
    }
}

 

 

// Custom_dialog.qml

import bb.cascades 1.0

Dialog {
    id: custom_dialog
    objectName: "custom_dialog"
    Container {
        background: Color.Black
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
        id: cnCustomDialog
        layout: StackLayout {
            orientation: LayoutOrientation.TopToBottom
        }
        objectName: "cnCustomDialog"
        CheckBox {
            id: chk
            objectName: "chk_first"
            text: "checked"
        }
    }
    onOpenedChanged: {
        if (opened) {
            navigation.addcomponentTocutomDialog();
        } else {
        }
    } 
    
}

 

//

when dialog is open I am adding some component dynamically.

 

// function to add the componenet is also called and componenet are added. but It's not visible on the page.

 

void App::addcomponentTocutomDialog() {
    qDebug() << "Display dialog";
    Dialog *pagedetail = root->findChild<Dialog *>("custom_dialog");
    if (pagedetail) {
        qDebug() << "page found";
        Container *container = pagedetail->findChild<Container *>(
                "cnCustomDialog");
        if (container) {
            qDebug() << "container found";
            Label *lbl_demo = Label::create().text(
                    "Demo label created on dialog");
            container->add(lbl_demo);           
        }

    }
}

 

Let me know what am I missing.

thanks in advance.

bskania.

Please use plain text.
Regular Contributor
_NishantShah
Posts: 76
Registered: ‎07-31-2012
My Device: Blackberry

Re: dynamically add components in dialog not working.

root->findChild takes object name as parameter.

 

Set objectName property of your custom component

 

 Custom_dialog {
            id:custom_dialog                       

            objectName: "custom_dialog"
        }

 

Hope it helps.

 

Regards,

Nishant Shah

Please use plain text.
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer

Re: dynamically add components in dialog not working.

Still Not working.
Please use plain text.