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
Highlighted
Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer
Accepted Solution

How to access Custom QML controls in C++ code...????

Hi All,

 

 

I have create a custom dialog to show loading popup and successfully added it in QML code but I am not getting way out to access this dialog in c++ code to close it when network connection is closed and response is received from web service.

 

Here is my code : 

import bb.cascades 1.0

Dialog {
    Container {
        preferredWidth: 400
        preferredHeight: 200
        background: Color.Black
        verticalAlignment: VerticalAlignment.Center
        horizontalAlignment: HorizontalAlignment.Center
        ActivityIndicator {
            id: loginIndicator
            objectName: "indicator"
            preferredWidth: 130
            preferredHeight: 130
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            onStopped: {
                if (errorTextid.text.trim() == "") {
                    var blogpage = goToWebView.createObject();
                    navPane.push(blogpage);
                }
            }
        }
        Label {
            text: "Please wait... Logging In"
        }
    } // Container
    onOpened: {
        // Reset the fire alarm since it is opened.
        loginIndicator.start()
    }
   
}

Please suggest something

Regards 

Deepak Charya
Developer
Posts: 16,999
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to access Custom QML controls in C++ code...????

you can access qml objects by using page->findChild<>() and the objectName property.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer

Re: How to access Custom QML controls in C++ code...????

[ Edited ]

Thanks simon for quick reply can u please elaborate with an example that would be really help full as if i am not adding this particular dialog on a page but attaching it with the container of the page using attachedObjects property

Deepak Charya
Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer

Re: How to access Custom QML controls in C++ code...????

Please suggest something this is how I am accessing this Dialog mentioned above 

// Navigation pane project template
import bb.cascades 1.0

NavigationPane {
    id: navigationPane
    Page {
        // page with a picture thumbnail
        Container {
            background: Color.Black
            layout: DockLayout {
            }
            Button {
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
                text: qsTr("Show detail")
                imageSource: "asset:///images/picture1thumb.png"
                onClicked: {
                    // show detail page when the button is clicked
                    load.open()
                   /* var page = getSecondPage();
                    console.debug("pushing detail " + page)
                    navigationPane.push(page);*/
                }
                /*property Page secondPage
                function getSecondPage() {
                    if (! secondPage) {
                        secondPage = secondPageDefinition.createObject();
                    }
                    return secondPage;
                }
                attachedObjects: [
                    ComponentDefinition {
                        id: secondPageDefinition
                        source: "DetailsPage.qml"
                    }
                ]*/
            }
        }
        attachedObjects: [
            LoadingPopUp {
                id: load
            }
        ]
    }
    onCreationCompleted: {
        // this slot is called when declarative scene is created
        // write post creation initialization here
        console.log("NavigationPane - onCreationCompleted()");

        // enable layout to adapt to the device rotation
        // don't forget to enable screen rotation in bar-bescriptor.xml (Application->Orientation->Auto-orient)
        OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
    }
}

 I am successfully using it in main.qml file and it appear on button click now problem is how to close it when response is received to navigate to next page.

 

Regards

 

Deepak Charya
Developer
Posts: 74
Registered: ‎03-04-2012
My Device: developer
My Carrier: developer

Re: How to access Custom QML controls in C++ code...????

thanks simon for showing the path finally i achieved it issue resolved

 

Solution for this problem is :

 

Dialog *popUpDialog =
bb::cascades::Application::instance()->findChild<Dialog*>(
"LoadingPop");
popUpDialog->close();

Deepak Charya