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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T
Accepted Solution

Unkown member issue when attempting to do propertyMap

In my app, I have a main.qml that has a TabbedPane.

The 2nd Pane is the LeadInformation.qml page, which has a NavigationPane to handled a multi-page questionaire.

From the first page, I have a menu option which pushes a BarcodeScan.qml page to scan the barcode.  When the data is read, I want to populate fields on the LeadInformation.qml .

 

I added a function in the ApplicationUI in order to parse the barcode data.

When the data is parsed, I am trying to use the propertyMap to update the fields on the page.

 

QmlDocument *qml = QmlDocument::create("asset:///LeadInformation.qml");
QDeclarativePropertyMap* propertyMap = new QDeclarativePropertyMap;

propertyMap->insert("iFirstName", data.mid(m_startSpot, m_endSpot - m_startSpot));

qml->setContextProperty("propertyMap", propertyMap);

 And in the LeadInformation.qml page

TextField {
                    id: tfLeadFirstName
                    hintText: "Lead First Name"
                    input.submitKey: SubmitKey.None
                    text: propertyMap.iFirstName;
                
                }

 In the qml page, I get an ! symbol and "Unknown member". 

 

I'm guessing I need to declare something somewhere else to get this to work.  The examples are for change the values on the main.qml page.  I haven't seen an example for changing the values on another page.

 

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Unkown member issue when attempting to do propertyMap

Which line is the ! against? Can you provide a screen shot please?

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: Unkown member issue when attempting to do propertyMap

I think it might be due to the qml page being a sub page or something.  I'm not sure.

 

propertyMapError_1.png

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Unkown member issue when attempting to do propertyMap

OK this relates to their being different contexts involved. Have a look at this post and the use of the global Qt object to share data across contexts and see if this helps:

 

http://supportforums.blackberry.com/t5/Native-Development/QML-Accessing-variables-defined-outside-a-...

 

 

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: Unkown member issue when attempting to do propertyMap

No, that doesn't seem to help.

 

I'm not trying to call a value from within the same QML page.  I'm trying to set the propertyMap from C++ code to a QML page that is not the main.qml.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Unkown member issue when attempting to do propertyMap

By placing it in the Qt object you should make it accessible from any QML page.....it's just a case of leveraging a globally accessible context I think.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Retired
Posts: 571
Registered: ‎06-25-2010
My Device: Z10
My Carrier: Vodafone

Re: Unkown member issue when attempting to do propertyMap

I don't have your full QML to try to recreate the issue but I believe the technique illustrated here will work for you. Basically in the onCreationCompleted handler for your outer and first Page, assign your propertyMap to Qt.propertyMap. Then you should be able to access Qt.propertyMap from anywhere.

 

import bb.cascades 1.2
NavigationPane {
    id: nav

    Page {

        onCreationCompleted: {
            Qt.propertyMap = propertyMap;
        }

        Container {

            Label {
                id: lbl
                text: propertyMap.iFirstName

            }

            Button {
                text: "Next"
                onClicked: {
                    console.log("Pushing secondPage");
                    var page = secondPageComponent.createObject();
                    nav.push(page);
                }
            }
        }
        attachedObjects: [
            ComponentDefinition {
                id: secondPageComponent
                Page {
                    id: secondPage
                    Container {
                        Label {
                            text: "Hello I am another page"
                        }
                        Label {
                            id: lbl2
                            text: Qt.propertyMap.iFirstName
                        
                        }
                    }
                }
            }
        ]
    }

}

 Give it a try and see if it works for you.

--------------------------------------------------------------------------------------------
Feel free to press the like button on the right side if you liked my attempts to help :-)
And please mark posts as solved if you think I found the solution or set you on its path. Thanks!
Follow me on Twitter: @mdwrim
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: Unkown member issue when attempting to do propertyMap

I'm still getting this error.

 

 

asset:///main.qml:10: ReferenceError: Can't find variable: propertyMap

 

The propertyMap is set in the ApplicationUI under a function called parseBarcode which parsed the barcode reader data and then sets each of the propertyMap variables.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: Unkown member issue when attempting to do propertyMap

This is what worked.

 

Instead of calling a source of the page, I just added the Page as an object.

 

In the main.qml, I added the NavigationPane (LeadInformation.qml)

import bb.cascades 1.0
import bb.system 1.0

TabbedPane {
    id: mainTabPane
    showTabsOnActionBar: true
    
    property bool databaseOpen: false
    
    tabs: [
        Tab {
            title: qsTr("User List")
            imageSource: "asset:///icons/ic_view_list.png"
            
            PageBase {
                databaseOpen: mainTabPane.databaseOpen
                page: "LeadsList.qml"
            }
        },
        Tab {
            title: qsTr("Add User")
            imageSource: "asset:///icons/AddSubscription.png"
            LeadInformation {
                
            }
        }
    ]
}

 In the Navigation Pane, that holds all the fields that the barcode data will fill in, I added the BarcodeScan page in the ComponentDefinition for the action item that calls the Barcode

import bb.cascades 1.0
import bb.system 1.0

NavigationPane {
    id: navigationPane
    property string barcodeOutput;
    property int currentLeadID;

    onCreationCompleted: {
        _app.setLastLeadID(0);
    }
    
    Page {
        id: leadsInformation
        titleBar: TitleBar {
            // Localized text with the dynamic translation and locale updates support
            title: qsTr("Lead Information") + Retranslate.onLocaleOrLanguageChanged
            appearance: TitleBarAppearance.Branded;            
        }  
    
        ScrollView {
            scrollViewProperties.scrollMode: ScrollMode.Vertical
            Container {
                layoutProperties: FlowListLayoutProperties {}
                clipContentToBounds: false

                Picker {
                    id: pkEmployee
                    title: "Bell and Howell Employee"
                    kind: PickerKind.Expandable
                    
                    rootIndexPath: []
                    dataModel: XmlDataModel {
                        id: dmEmployees
                        source: "xml/employees.xml" }
                    
                    pickerItemComponents: [
                        
                        PickerItemComponent {
                            type: "employee"
                            content: Container {
                                Label {
                                    text: pickerItemData.email
                                }
                            }
                        }
                    
                    ]
                    
                    onSelectedValueChanging: {
                        console.debug("selectedIndex = " + selectedIndex(0))
                        var selectedEmployee = dataModel.data([0, selectedIndex(0)])
                        console.debug("selectedEmployee 0,0 email = " + selectedEmployee.email)
                        
                        lbEmployee.text = selectedEmployee.email  
                    }
                    
                    onSelectedValueChanged: {
                        console.debug("selectedIndex = " + selectedIndex(0))
                        var selectedEmployee = dataModel.data([0, selectedIndex(0)])
                        console.debug("selectedEmployee 0,0 email = " + selectedEmployee.email)
                        
                        lbEmployee.text = selectedEmployee.email
                        
                        if(lbEmployee.text.length > 2 && lbSelectedShow.text.length > 2) {
                            if(aiNextButton.enabled == false) { aiNextButton.enabled = true }
                        }
                    }
                }
                Label {
                    id: lbEmployee
                    textStyle.fontStyle: FontStyle.Italic
                    textStyle.fontWeight: FontWeight.Bold
                }
                
                Picker {
                    id: pkShow
                    title: "Show"
                    kind: PickerKind.Expandable
                    
                    rootIndexPath: []
                    dataModel: XmlDataModel { source: "xml/show.xml" }
                    
                    pickerItemComponents: [
                        PickerItemComponent {
                            type: "show"
                            
                            content: Container {
                                Label {
                                    text: pickerItemData.name
                                }
                            }
                        }
                    ]
                    
                    onSelectedValueChanging: {
                        console.debug("selectedIndex = " + selectedIndex(0))
                        var selectedShow = dataModel.data([0, selectedIndex(0)])
                        console.debug("selectedShow 0,0 name = " + selectedShow.name)
                        
                        lbSelectedShow.text = selectedShow.name
                    }
                    
                    onSelectedValueChanged: {
                        console.debug("selectedIndex = " + selectedIndex(0))
                        var selectedShow = dataModel.data([0, selectedIndex(0)])
                        console.debug("selectedShow 0,0 name = " + selectedShow.name)
                        
                        lbSelectedShow.text = selectedShow.name
                        
                        if(lbEmployee.text.length > 2 && lbSelectedShow.text.length > 2) {
                            if(aiNextButton.enabled == false) { aiNextButton.enabled = true }
                        }
                    }
                
                }
                
                Label {
                    id: lbSelectedShow
                    textStyle.fontStyle: FontStyle.Italic
                    textStyle.fontWeight: FontWeight.Bold
                }
                
                Header {
                    title: "Lead Information"
                }
                
                TextField {
                    id: tfLeadFirstName
                    hintText: "Lead First Name"
                    input.submitKey: SubmitKey.None
                
                }
                
                TextField {
                    id: tfLeadLastName
                    hintText: "Lead Last Name"
                    input.submitKey: SubmitKey.None
                
                }
                
                Header {
                    title: "Company Information"
                
                }
                TextField {
                    id: tfCompanyName
                    hintText: "Company Name"
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfJobTitle
                    hintText: "Job Title"
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfAddrLine1
                    hintText: "Address Line 1"
                    input.submitKey: SubmitKey.None
                }
                TextField {
                    id: tfAddrLine2
                    hintText: "Address Line 2"
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfCity
                    hintText: "City"
                    input.submitKey: SubmitKey.None
                }
                TextField {
                    id: tfStateRegion
                    hintText: "State / Region"
                    input.submitKey: SubmitKey.None 
                
                }
                TextField {
                    id: tfCountry
                    hintText: "Country"
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfPostalCode
                    hintText: "PostalCode"
                    input.submitKey: SubmitKey.None
                
                }
                Header {
                    title: "Contact Information"
                
                }
                TextField {
                    id: tfPhone
                    hintText: "Phone"
                    inputMode: TextFieldInputMode.PhoneNumber
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfPhoneExt
                    hintText: "Phone Extension"
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfFax
                    hintText: "Fax"
                    inputMode: TextFieldInputMode.PhoneNumber
                    input.submitKey: SubmitKey.None
                
                }
                TextField {
                    id: tfEmail
                    hintText: "eMail"
                    inputMode: TextFieldInputMode.EmailAddress
                    input.submitKey: SubmitKey.None
                
                }
            }
        }
        actions: [
            ActionItem {
                id: aiNextButton
                enabled: false
                title: qsTr("Purchasing Timeframe") + Retranslate.onLocaleOrLanguageChanged
                ActionBar.placement: ActionBarPlacement.OnBar
                imageSource: "asset:///icons/ic_next.png"
                
                onTriggered: {
                    currentLeadID = _app.getLastLeadID();
                    if(currentLeadID == 0) {
                        // Create new Sales Leads
                        _app.createLeadRecord(
                            tfLeadFirstName.text,
                            tfLeadLastName.text,
                            tfCompanyName.text,
                            tfJobTitle.text,
                            tfAddrLine1.text,
                            tfAddrLine2.text,
                            tfCity.text,
                            tfStateRegion.text,
                            tfCountry.text,
                            tfPostalCode.text,
                            tfEmail.text,
                            tfPhone.text,
                            tfPhoneExt.text,
                            tfFax.text,
                            lbEmployee.text,
                            lbSelectedShow.text);
                        console.debug("New Sales Lead - Create")
                    } else {
                        // Update current Sales Lead
                        _app.updateLeadRecord(
                        	currentLeadID,
                            tfLeadFirstName.text,
                            tfLeadLastName.text,
                            tfCompanyName.text,
                            tfJobTitle.text,
                            tfAddrLine1.text,
                            tfAddrLine2.text,
                            tfCity.text,
                            tfStateRegion.text,
                            tfCountry.text,
                            tfPostalCode.text,
                            tfEmail.text,
                            tfPhone.text,
                            tfPhoneExt.text,
                            tfFax.text,
                            lbEmployee.text,
                            lbSelectedShow.text);
                            console.debug("Existing Sales Lead - Update Sales Lead ID: " + currentLeadID)
                    }
                    _app.readLeadRecords(); // Refresh the list view.
                    _marketingWS.insertSalesLead(1);
                    //navigationPane.push(purchasingTimeframeDefinition.createObject());
                    
                }                
            },
            ActionItem {
                id: aiScanButton
                enabled: true
                title: qsTr("Scan Barcode") + Retranslate.onLocaleOrLanguageChanged
                ActionBar.placement: ActionBarPlacement.InOverflow
                imageSource: "asset:///icons/ic_scan_barcode.png"
                
                onTriggered: {
                    navigationPane.push(barcodeScanDefinition.createObject())
                }
            
            }
        
        ]
        
        attachedObjects: [
            // Definition of the second Page, used to dynamically create the Page above.
            ComponentDefinition {
                id: purchasingTimeframeDefinition
                source: "PurchasingTimeframe.qml"
            },
            ComponentDefinition {
                id: barcodeScanDefinition
                BarcodeScan {
                    
                }
            }
        ]
        
        
    }
    
    onPopTransitionEnded: {
        // Destroy the popped Page once the back transition has ended.
        page.destroy();
    }
    backButtonsVisible: false

}

 Then, in the BarcodeScan.qml page, I just referenced the fields and added them to the white list.  Instead of calling the C++ code for parsing the data, I just parsed it on the page.  QString provides some better string handling than the regular string, so this isn't as clean as I wanted it to be.

Page {
    property string decodeString
    property string tmpString
    property int initStartSpot: 0;
    property int startSpot: 0;
    property int endSpot: 0;
    property int x:0;
    
    property int vcard: 0
    property int vcard2_1: 1
    property int vcard3: 2
    property int print2013: 3
    property int codeType: 0
    
    Container {
        id: cMain
        layout: StackLayout {

        }
        horizontalAlignment: HorizontalAlignment.Center
        verticalAlignment: VerticalAlignment.Center
        background: Color.create(0x9CDCF6)
        
        Container {
            id: cCameraReader

            layout: AbsoluteLayout {

            }
            background: Color.White
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center

            Camera {
                id: camera
                preferredWidth: 450
                preferredHeight: 450

                onCameraOpened: {
                    camera.startViewfinder();
                }
            }

            BarcodeDetectorVisuals {
                id: bdvScanner
                preferredWidth: 450
                preferredHeight: 450
                barcodeDetector: barcodeDetector
                
                onDetected: {
                    // Set the UserID to 0
                    _app.setLastLeadID(0);

                    decodeString = data;
                    dataArea.text = decodeString;
                    
                    if(decodeString.indexOf("VCARD") > 0) {
                        if(decodeString.indexOf("VERSION:3.0") > 0) {
                            codeType = vcard3;
                        } else if(decodeString.indexOf("VERSION:2.1") > 0) {
                            codeType = vcard2_1;
                        } else {
                            codeType = vcard;
                        }
                    
                    } else {
                        codeType = print2013;
                    }
                    
                    dataArea.text += "\n " + codeType;
                    
                    switch(codeType) {
                        case vcard2_1:
                        case vcard:
                        case vcard3:
                            // Get Name
                            tmpString = decodeString.substr(decodeString.indexOf("N:"), decodeString.indexOf("TITLE:"));
                            
                            tfLeadFirstName.text = tmpString.substr(0, tmpString.indexOf(";"));
                            tfLeadLastName.text = tmpString.substr(tmpString.indexOf(";") + 1, tmpString.length);
                            break;
                        case print2013:
                            //qDebug() << " Last End spot = " << decodeString.lastIndexOf(QString("$"));
                            //qDebug() << " $ counts = " << decodeString.count(QString("$"));
                            startSpot = 0;
                            initStartSpot = decodeString.indexOf("$", startSpot + 1);
                            for(x=0; x < 22; x++) {
                                endSpot = decodeString.indexOf("$", startSpot + 1);
                                
                                dataArea.text += "\n x:" + x + " endSpot = " + endSpot;
                                if(endSpot != -1) {
                                    switch(x) {
                                        case 0:
                                            // badge ID
                                            //qDebug() << " Badget ID = " << decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 1:
                                            // blank or Show ID
                                            //qDebug() << " Show ID = " << decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 2:
                                            // First Name
                                            tfLeadFirstName.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 3:
                                            //Last Name
                                            tfLeadLastName.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 4:
                                            //Title
                                            tfJobTitle.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 5:
                                            //Company
                                            tfCompanyName.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 6:
                                            //AddrLine1
                                            tfAddrLine1.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 7:
                                            //AddrLine2
                                            tfAddrLine2.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 8:
                                            //City
                                            tfCity.text =  decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 9:
                                            //StateRegion
                                            tfStateRegion.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 10:
                                            //PostalCode
                                            tfPostalCode.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 11:
                                            //Country
                                            tfCountry.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 12:
                                            //Phone
                                            tfPhone.text =  decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 13:
                                            //PhoneExt
                                            tfPhoneExt.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 14:
                                            //Fax
                                            tfFax.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 15:
                                            //LeadEmail
                                            tfEmail.text = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 16:
                                            //RegClass
                                            //tftext = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 17:
                                            //PrincipalBusiness
                                            //tftext = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 18:
                                            //Primary Job Function:
                                            //tftext = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 19:
                                            //Influence in your company's buying decision
                                            //tftext = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 20:
                                            //Number of Employees
                                            //tftext = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 21:
                                            //Annual Sales Volume:
                                            //tftext = decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                        case 22:
                                            //Products you are interested in (Multiple Answer/Comma Delimited)
                                            //leadContainer.tftext =  decodeString.substr(startSpot, endSpot - startSpot);
                                            break;
                                    }
                                    
                                    startSpot = endSpot + 1;
                                } else {
                                    break;
                                }
                            }
                        }

                    navigationPane.pop(); 
                }
            }
        }
        attachedObjects: [

            BarcodeDetector {
                id: barcodeDetector
                formats: BarcodeFormat.Any
                camera: camera 
            }
        ]
        TextArea {
            id:dataArea
            text: "<Data>"
            textFormat: TextFormat.Auto
            maximumLength: 400

        }
  
    }
    onCreationCompleted: {
       if (camera.allCamerasAccessible) {
            camera.open();
            console.debug("rear camera opened")
       } else {
          	dataArea.text = "Cameras are not accessible"
        }
    }
}

 

This is the solution.  It works.

Not the solution I was looking for, but I don't have the time right now to try it again.

My guess is, that the propertyMap will also work now with the way I am handling the Page calls.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment