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
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone
Accepted Solution

problem with findChild

[ Edited ]

Hi,

 

I have designed whole layouts in QML. And writing functionalities in C++. 

 

My Problem is below where main.qml is my root content in cpp file 

import bb.cascades 1.0

TabbedPane {
    showTabsOnActionBar: true
    objectName: "objectCrypt"
    Tab {
        title: qsTr("Private")
        imageSource: "asset:///actionbar/private.png"
        NavigationPane {
            id:navPane
           .
           .
           .
           .
           ImageButton {
                id: noteicon
                defaultImageSource: "asset:///images/noteicondef.png"
                pressedImageSource: "asset:///images/noteiconpre.png"
                disabledImageSource: "asset:///images/noteicondis.png"
                layoutProperties: AbsoluteLayoutProperties {
                    positionX: 347.0
                    positionY: 580.0
                }
                scaleX: 2.0
                scaleY: 2.0
                onClicked: {
                    var np = notePage.createObject();
                    navPane.push(np);
                }
           }
           .
           .
           .
           .
     attachedObjects: [
        ComponentDefinition {
            id: notePage
            source: "note.qml"
        }
      ]

 And my note.qml is something with a ListView

 

import bb.cascades 1.0
import bb.data 1.0

Page {
    resizeBehavior: PageResizeBehavior.None
    Container {
        background:bg.imagePaint
        layout: AbsoluteLayout {}
          ListView {
            id:notelistview
            objectName: "notelistview"
            layoutProperties: AbsoluteLayoutProperties {
                positionX: 0.0
                positionY: 129.0
            }
            opacity: 0.9
            dataModel: groupDataModel
            listItemComponents: [
                ListItemComponent {
                    id:row
                    type: "item"
                    .
                    .
                    .
                    .
                }
             ]
                    .
                    .
                    .
                    .
}

 

And my C++ class is shown below

ClassName::ClassName(bb::cascades::Application *app)
: QObject(app)
{
    // create scene document from main.qml asset
    // set parent to created document to ensure it exists for the whole application lifetime
    QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
    qml->setContextProperty("objectCrypt",this);
    // create root object for the UI
    root = qml->createRootObject<AbstractPane>();
    // set created root object as a scene


    fetchNotes();
    app->setScene(root);
}

void ClassName::fetchNotes(){
			listView = new ListView;
			listView = root->findChild<ListView*>("notelistview");
			QTemporaryFile file(("data/files/database/mySQLFile.db"));
			QVariant list;
			if (file.open()) {
				SqlDataAccess sda("data/files/database/mySQLFile.db");
				list = sda.execute("SELECT * FROM Notes");
			}
			model = new GroupDataModel(QStringList() << "title"<<"date"<<"filename");
			model->clear();
			model->setGrouping(ItemGrouping::None);
			int Total = list.value<QVariantList>().length();
			showMyToast(QString::number(Total));
			//emit sizeChanged();
			model->insertList(list.value<QVariantList>());
			listView->setDataModel(model);
}

 i am not getting reference to ListView....

 

This is the error shown in the console...

 

Process 63484108 (ClassName) terminated SIGSEGV code=1 fltno=11 ip=798f8ed0(/base/usr/lib/libbbcascades.so.1@_ZNK2bb8cascades8ListView8selectedEv+0xb67) mapaddr=000f8ed0. ref=00000010

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

Re: problem with findChild

you call fetchNotes before you create the page containing the listView.
You can either wait until the button to create it was clicked or create it directly when loading the main.qml.
----------------------------------------------------------
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
Highlighted
Developer
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone

Re: problem with findChild

Yep.. it is solved. i have given fetchNotes() in the button click after creating the note.qml.

Thanks again... Smiley Happy