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
Contributor
subramanyaraviteja
Posts: 20
Registered: ‎09-12-2012
My Device: Developer
My Carrier: Docomo

GroupDataModel was not taking objects

 

Here i have to display the objects in the output so i have defined a class for that and created a object for that  and i give that object to groupdatamodel but its not working check it once

 

here is the cpp file in that cpp i get the listview in main.qml and set the groupdatamodel

 

  GroupDataModel *m = new GroupDataModel(QStringList()<<"name");

//    		 QList<QObject *> lst;
//    		 lst << new Name("Test");

//    		QVariantMap *map;
//    		map->insert("name","RaviTeja");
//          m->insert(map);

//    	    lst->append(new Name("RaviTeja"));
//    	    m->insertList(lst);

    	    m->insert(new Name("RaviTEja"));

            ListView *list_view = root->findChild<ListView*>("listView");
            if(list_view) list_view->setDataModel(m);

 

here i have created an object of Name class which is a subclass of QObject and set into the model and the model is given to listview but in the output the Name class name variable data(RaviTeja) is not showing in listview

 

main.qml

========

 

// Grid view with detail project template
import bb.cascades 1.0

NavigationPane {
    id: navigationPane
    firstPage: Page {
        id: pgMain
        content: Container {
            layout: DockLayout {
            }
            ListView {
                id: listView
                // set object name to let listView to be discoverable from C++
                objectName: "listView"
                layout: GridListLayout {}
                listItemComponents: [
                    // define component which will represent list item GUI appearence
                    ListItemComponent {
                        type: "item"
                        // list item GUI appearence component is defined in external MyListItem.qml file
//                        MyListItem {}
                    Label{
                        text:ListItemData.name
                    }
                  }
                ]
                onTriggered: {
                    console.log("selected_index: " + indexPath)
                    var curr_item = dataModel.data(indexPath)
                    // show detail page for selected item
                    setDetailItem(curr_item)
                }
                horizontalAlignment: HorizontalAlignment.Center
                verticalAlignment: VerticalAlignment.Center
            }
        }
    }
    attachedObjects: [
        ComponentDefinition {
            id: secondPageDefinition
            content: Page {
                property alias text: lblText.text
                property alias image: imgView.imageSource
                id: pgDetail
                paneProperties: NavigationPaneProperties {
                    backButton: ActionItem {
                        onTriggered: { navigationPane.pop(); }
                    }
                }
                content: Container {
                    layout: StackLayout {
                    }
                    Label {
                        id: lblText
                        textStyle.base: SystemDefaults.TextStyles.TitleText
                        //textStyle.color: Color.Yellow
                        horizontalAlignment: HorizontalAlignment.Center
                    }
                    ImageView {
                        id: imgView
                        scalingMethod: ScalingMethod.AspectFit
                        layoutProperties: StackLayoutProperties {
                            spaceQuota: 1.0 // the image fills rest of the Page

                        }
                        verticalAlignment: VerticalAlignment.Center
                        horizontalAlignment: HorizontalAlignment.Center
                    }
                }
            }
        }
    ]
    function setDetailItem(item) {
        // show detail page
        var page = secondPageDefinition.createObject();
        page.text = item.text
        page.image = item.image
        navigationPane.push(page)
    }
    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;
    }
}

 

Please use plain text.
Developer
kylefowler
Posts: 526
Registered: ‎05-17-2009
My Device: 9900
My Carrier: ATT

Re: GroupDataModel was not taking objects

you need an itemType(data,index) function in the ListView qml to tell it to show one of your list view components of type "item"
Like all of my posts
Please use plain text.
Contributor
subramanyaraviteja
Posts: 20
Registered: ‎09-12-2012
My Device: Developer
My Carrier: Docomo

Re: GroupDataModel was not taking objects

ya iam using like this ListItemData.name but not working  then how to get data in qml

Please use plain text.