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
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

How to start Activity Indicator into C++ file?

Hi All,

 

Need help to create a Activity Indicator into C++ file. Below is my code

mActivityIndicator=findChild<ActivityIndicator*>("indicator1");

 but it crash my application. dont know where am doing wrong. Please suggest me a solution

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to start Activity Indicator into C++ file?

[ Edited ]

I'd need a bit more context. Are you inflating your layout with QmlDocument and createRootObject()?  e.g.

QmlDocument* qml = QmlDocument::create("asset:///MyPage.qml");
Container* mRoot = qml->createRootObject<Container>();

 In this example, you'd need to use

mActivityIndicator = mRoot->findChild<ActivityIndicator*>("indicator1");

 



Did this post help you? If so, please make sure to "like" it!
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to start Activity Indicator into C++ file?

Thanks for reply, but i am making layout into qml file. And want to create activity indicator into c++ and call that object into  qml file. That i want to do.

 

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to start Activity Indicator into C++ file?

In which case, you're going about it in the wrong way. findChild is only used when you've already declared your ActivityIndicator in your QML. To create an ActivityIndicator and run it, you'll need to use:

 

ActivityIndicator* activity = ActivityIndicator::create();
activity->start();

 And then add() it to a container in your C++ code.



Did this post help you? If so, please make sure to "like" it!
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to start Activity Indicator into C++ file?

below is my qml file

// Default empty project template
import bb.cascades 1.0
import "Common"
import Network.PostHttp 1.0
import Network.GetHttp 1.0
import Network.GetLeadsHttp 1.0
import "controls"
import my.library 1.0
import bb.system 1.0

// the third tab has its own pane which will be automatically
// set as the active pane when the tab becomes active

Page {
    id: defaultPane
    actions: [
        // An action item that calls the C++ function that retrieves
        // the contact list
        ActionItem {
            title: "Scan"
            onTriggered: leadValue.post("EventId=&UserId=" + _httpsample.getUserID, "00DF0000000BpyH!AQgAQAA4lAvO3Q3vNxIOth7XDuY1F3RLBI_ASQV43ydoIpA6sU_GOgFWdrGtQNOJsBTdgI7A4cBD5Q40NTECUW32vM1X6Q4g")
            ActionBar.placement: ActionBarPlacement.OnBar
            imageSource: "asset:///images/scan_unfocus_mode.png"
        },
        ActionItem {
            title: "Leads"
            
            ActionBar.placement: ActionBarPlacement.OnBar
            imageSource: "asset:///images/lead_unfocus_mode.png"
        }
    ]
    Container {
        id: leadContainer
        background: Color.create("#F4F4EE")
        layout: StackLayout {
        }
        Container {
            background: Color.create("#0A6FA6")
            preferredWidth: 768.0
            preferredHeight: 110
            // maxHeight: 140
            topPadding: 10.0
            layout: DockLayout {
            }
            Container {
                preferredWidth: 220
                leftPadding: 20
                topPadding: 20
                horizontalAlignment: HorizontalAlignment.Left
                Label {
                    id: leadCount
                    text: ""
                    textStyle.fontSize: FontSize.Small
                    textStyle.color: Color.White
                    textStyle.fontWeight: FontWeight.Bold

                    //textStyle.textAlign: TextAlign.Right
                }
            }
            Container {
                // preferredWidth: 0
                // preferredHeight: 0
                // horizontalAlignment: HorizontalAlignment.Left
                leftPadding: 270.0
                //topPadding: 10
                //maxHeight: 50.0
                TextField {
                    id: filterList
                    objectName: "txtSrch"
                    hintText: "Search Lead"
                    textStyle.fontSize: FontSize.XSmall
                    preferredWidth: 480.0
                    horizontalAlignment: HorizontalAlignment.Center
                }
            }
        }
        // A list that has two list item components, one for a header
        // and one for contact names. The list has an object name so
        // that we can set the data model from C++.
       
        Container {
            id: containerList

            // topPadding: 20.0
           // background: Color.create("#F4F4EE")
            topPadding: 250.0
            ActivityIndicator {
              id: leadProgressbar
                objectName: "indicator1"
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
                preferredWidth: 200
                preferredHeight: 200
                //running: true
            // onStarted: 
               // onStopped: containerList.topPadding = 0;
            }
            ListView {
                
                //objectName: "getleadList"
                verticalAlignment: VerticalAlignment.Center
                horizontalAlignment: HorizontalAlignment.Center
                layout: StackListLayout {
                }
                // A simple data model is loaded with just a header.
                // This will be replaced when we load the real one
                // from C++.
                dataModel: leadsList.m_dataModel
                listItemComponents: [
                    // The header list item displays a title along with a counter
                    // that displays the number of children
                    ListItemComponent {
                        type: "item"
                        Container {
                            id: leadList
                            // topPadding: 85
                            layout: DockLayout {
                            }
                            Container {
                                preferredWidth: 500
                                preferredHeight: 170
                                horizontalAlignment: HorizontalAlignment.Left
                                leftPadding: 30.0
                                //topPadding: 60.0
                                Label {
                                    text: ListItemData.Firstname + " " + ListItemData.Lastname
                                    textStyle.fontSize: FontSize.Medium
                                    textStyle.color: Color.DarkBlue
                                    multiline: true
                                }
                                Label {
                                    text: ListItemData.Company
                                    textStyle.fontSize: FontSize.XSmall
                                    textStyle.color: Color.Black
                                    multiline: true
                                }
                                ImageView {
                                    id: rating
                                    imageSource: leadList.imageSource()
                                    horizontalAlignment: HorizontalAlignment.Left
                                }
                            }
                            Container {
                                //preferredWidth: 100
                                //preferredHeight: 70
                                //horizontalAlignment: HorizontalAlignment.Right
                                verticalAlignment: VerticalAlignment.Top
                                leftPadding: 560
                                topPadding: 10
                                Label {
                                    text: leadList.splitFollowUpDate()
                                    textStyle.fontSize: FontSize.XSmall
                                    textStyle.color: Color.Black
                                    //textStyle.textAlign: TextAlign.Right
                                }
                            }
                            Divider {
                                horizontalAlignment: HorizontalAlignment.Left
                                opacity: 1.0
                            }
                            function splitFollowUpDate() {

                                //console.log("Next Follow Up date.."+ListItemData.NextFollowUpdate);
                                if (ListItemData.NextFollowUpdate != null) {
                                    var index = ListItemData.NextFollowUpdate.indexOf(" ");
                                    if (index > 0) {
                                        return ListItemData.NextFollowUpdate.substring(0, index);
                                    }
                                }
                            }
                            function imageSource() {
                               // console.log("Rating value..." + ListItemData.leadRating);
                                if (ListItemData.leadRating == "0") {
                                    return "asset:///images/Star_0.png";
                                } else if (ListItemData.leadRating == "1") {
                                    return "asset:///images/Star_1.png";
                                } else if (ListItemData.leadRating == "2") {
                                    return "asset:///images/Star_2.png";
                                } else if (ListItemData.leadRating == "3") {
                                    return "asset:///images/Star_3.png";
                                } else if (ListItemData.leadRating == "4") {
                                    return "asset:///images/Star_4.png";
                                } else if (ListItemData.leadRating == "5") {
                                    return "asset:///images/Star_5.png";
                                }
                            }
                        }
                    }
                // The contact list item displays the name of the contact

                // The contact list item displays the name of the contact
                ]
                touchPropagationMode: TouchPropagationMode.Full
                onTriggered: {
                    //emailValidation.show()
                    
                    var selectedItem = dataModel.data(indexPath);
                    console.log("ON List Scanned time" + selectedItem.ScanTime);
                    if (selectedItem.Email != null) leadValue.getEmail = selectedItem.Email;
                    if (selectedItem.Firstname != null) leadValue.getfName = selectedItem.Firstname;
                    if (selectedItem.Lastname != null) leadValue.getlName = selectedItem.Lastname;
                    
                    if (selectedItem.Company != null) {
                        leadValue.getCompName = selectedItem.Company;
                    }else{
                        leadValue.getCompName="";
                    }
                    
                    if (selectedItem.leadRating != null) leadValue.getRating = selectedItem.leadRating;
                    if (selectedItem.SurveyAnswer1 != null) {
                        leadValue.getSurveyAnswer1 = selectedItem.SurveyAnswer1;
                    }else{
                        leadValue.getSurveyAnswer1 ="";
                    }
                    
                    if (selectedItem.SurveyAnswer2 != null) {
                        leadValue.getSurveyAnswer2 = selectedItem.SurveyAnswer2;
                    }else{
                        leadValue.getSurveyAnswer2 = "";
                    }
                    
                    if (selectedItem.SurveyAnswer3 != null) {
                        leadValue.getSurveyAnswer3 = selectedItem.SurveyAnswer3;
                    }else{
                        leadValue.getSurveyAnswer3 = "";
                    }
                    if (selectedItem.state != null){
                        leadValue.getState = selectedItem.state;
                    }else{
                        leadValue.getState = "";
                    }
                        
                     
                    if (selectedItem.City != null){
                        leadValue.getCity = selectedItem.City;
                    }else{
                        leadValue.getCity ="";
                    } 
                    if (selectedItem.Phone != null) {
                        leadValue.getPhoneNo = selectedItem.Phone;
                    }else{
                        leadValue.getPhoneNo ="";
                    }
                    if (selectedItem.Notes != null){
                        leadValue.getNotes = selectedItem.Notes;

                    } else{
                        leadValue.getNotes = "";

                    }                   
                    if (selectedItem.FollowupTypes != null){
                        leadValue.getFollowUpType = selectedItem.FollowupTypes;
                    }else{
                        leadValue.getFollowUpType = "";
                    }
                    
                    if (selectedItem.NextFollowUpdate != null){
                        console.log("Follow date is not null");
                        leadValue.getFollowUpDate = selectedItem.NextFollowUpdate;
                    }else{
                        console.log("Follow date is  null");
                        leadValue.getFollowUpDate ="";
                    }
                    
                    if (selectedItem.eventTile != null){
                        leadValue.getEventTitle = selectedItem.eventTile;
                    }else{
                        leadValue.getEventTitle = "";
                    }
                    
                    if (selectedItem.Barcodeid != null){
                        leadValue.getBarcodeId = selectedItem.Barcodeid;
                    }else{
                        leadValue.getBarcodeId = "";
                    }
                    
                    if (selectedItem.ScanTime != null) {
                        leadValue.getScanTime = selectedItem.ScanTime
                    }else{
                        leadValue.getScanTime ="";
                    }
                    if (selectedItem.Designation != null){
                        leadValue.getDesignation = selectedItem.Designation
                    } else{
                        leadValue.getDesignation = ""
                    }
                    if (selectedItem.EventId != null) {
                        leadValue.getEventId = selectedItem.EventId
                    } else {
                        leadValue.getEventId = ""
                    }
                    if (selectedItem.RecordId != null) {
                        leadValue.getRecordId = selectedItem.RecordId
                    } else {
                        leadValue.getRecordId = ""
                    }
                    /*  leadValue.getCompName = selectedItem.Company;
                     * leadValue.getRating = selectedItem.leadRating;
                     * leadValue.getSurveyAnswer1 = selectedItem.SurveyAnswer1;
                     * leadValue.getSurveyAnswer2 = selectedItem.SurveyAnswer2;
                     * leadValue.getSurveyAnswer3 = selectedItem.SurveyAnswer3;
                     * leadValue.getState = selectedItem.state;
                     * leadValue.getCity = selectedItem.City;
                     * leadValue.getPhoneNo = selectedItem.Phone;
                     * leadValue.getNotes = selectedItem.Notes;
                     * 
                     * leadValue.getFollowUpType = selectedItem.FollowupTypes;
                     * leadValue.getFollowUpDate = selectedItem.NextFollowUpdate;
                     * leadValue.getEventTitle = selectedItem.eventTile;
                     * leadValue.getBarcodeId = selectedItem.Barcodeid;
                     * leadValue.getScanTime = selectedItem.ScanTime;*/
                    //console.log(dataModel.childCount(0));
                    console.log(leadValue.getFollowUpType + " Email:" + leadValue.getEmail);
                    var lead_details = leadDetails.createObject();
                   
                    navigationPane.push(lead_details);
                }
                onDataModelChanged:{
                
                    console.log("Data Model changed:"+ dataModel.childCount(0))
                    leadCount.text="Leads "+dataModel.childCount(0)
                    
                    containerList.topPadding = 0;
                 }
            }
        }
        // The activity indicator has an object name set so that
        // we can start and stop it from C++
    }
    attachedObjects: [
        GetLeadsHttp {
            id: leadValue
        },
        ComponentDefinition {
            id: leadDetails
            source: "LeadDetailsPage.qml"
        },
        SystemDialog {
            id: emailValidation
            title: "Alert!"
            body: "Please enter a valid Email Id"
            
        }
    ]
   onCreationCompleted: {
        leadProgressbar.start()
        leadValue.post("EventId=&UserId=" + _httpsample.getUserID, _httpsample.getAccessToken)
    }
  
}

 in this am declaring Activity Indictor wiht object

below is the code in c++

mActivityIndicator = this->findChild<ActivityIndicator*>("indicator1");

mActivityIndicator->start()

but my app get crashed when it comes on "mActivityIndicator->start()".

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to start Activity Indicator into C++ file?


erAjayGoyal wrote:

 

mActivityIndicator = this->findChild<ActivityIndicator*>("indicator1");

mActivityIndicator->start()

but my app get crashed when it comes on "mActivityIndicator->start()".


Again, read what I wrote above. You only use findChild when you've declared the ActivityIndicator in QML. You need to use ActivityIndicator::create() and put the resulting object into a container via C++.



Did this post help you? If so, please make sure to "like" it!
Developer
Posts: 107
Registered: ‎05-11-2011
My Device: BlackBerry Z10 LE
My Carrier: AirTel

Re: How to start Activity Indicator into C++ file?

Hi,

 

also you can use system dialog to prevent user interact with controls during data is loading.

 

QML

import bb.cascades 1.0

Page {

    content: Container {

    }
    attachedObjects: [
        Dialog {
            id: dialogProgress
            Container {
                preferredWidth: 768
                preferredHeight: 1280
                background: Color.create(0.0, 0.0, 0.0, 0.5)

                layout: DockLayout {
                }

                Container {
                    maxHeight: 397
                    horizontalAlignment: HorizontalAlignment.Center
                    verticalAlignment: VerticalAlignment.Center
                    ActivityIndicator {
                        preferredWidth: 200
                        preferredHeight: 200
                        running: true
                    }
                }
            }
        }
    ]

    onCreationCompleted: {
        app.loadStatusChanged.connect(onLoadStatusChanged);
        app.loadSchedule();
    }

    function onLoadStatusChanged(val) {
        if (val == 0) {
            dialogProgress.open();
        } else {
            dialogProgress.close();
        }
    }
}

hpp

signals:
	void loadStatusChanged(int);
emit loadStatusChanged(0);  //For start loading dialog
or
emit loadStatusChanged(1);  // for stop loading dialog

1. first make one signal in hpp

2. and connect this signal with method in qml

3. emit signal whenever require with 0 or 1 perameter from cpp

 

for more help about dialog pls refer

 

https://developer.blackberry.com/cascades/documentation/ui/dialogs_toasts/tutorial_create_a_custom_d...

 

you can use app in qml by this code in cpp

 

QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
qml->setContextProperty("app", this);
root = qml->createRootObject<AbstractPane>();
app->setScene(root);

Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to start Activity Indicator into C++ file?

Hi raj,

 

Thanks for reply, and waht about ListView.

Am creating listview in c++ file like below

leads_list=>findChild<ListView*>("getleadList");

then calling "getleadList" ob ject into qml file.

but my app is crashing.

Developer
Posts: 188
Registered: ‎07-19-2012
My Device: Z10 LE
My Carrier: Three

Re: How to start Activity Indicator into C++ file?

If you're using the same QML as above, you need to uncomment the objectName: "getleadList" line.



Did this post help you? If so, please make sure to "like" it!
Regular Contributor
Posts: 97
Registered: ‎04-19-2012
My Device: BB Torch-9800
My Carrier: *

Re: How to start Activity Indicator into C++ file?

Okey, let me try this way.