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: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

C++ Find Instance of Component Defenition

I have a sheet which is made from a component defentiion.

 

ComponentDefinition {
            id: submitSheetDef
            source: "SubmitScreen.qml"
        }

 The object name of the sheet is defined within the QML of submitScreen.

Sheet {
    objectName: "submitSheet"
    // code here
}

 I'm trying to find the sheet using c++ so I can dynamically set some of the values found within the submit sheet.

AbstractPane *root = Application::instance()->scene();
Sheet* submitSheet = root->findChild<Sheet*>("submitSheet");
qDebug() << "submit sheet exists? " << submitSheet;

 When I run the code above nothing is found. Where do I need to set the obect name of my sheet in order to access it from c++ using findChild?

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: C++ Find Instance of Component Defenition

How is the sheet instantiated? Does it have a parent?
It might be easier to pass the newly created sheet to C++ class as a function parameter and to store it in a member variable.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: C++ Find Instance of Component Defenition

The sheet is created and opened from the defenition like so

 

submitSheetDef.createObject().open
// At same time open a camera
app.invokeCamera()
// Once the camera sheet has been closed a seperate c++ function runs
// which is supposed to find the sheet and set a few values

 

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: C++ Find Instance of Component Defenition

I don't know if this will work or not, just an idea:

Try passing an id of item in which you're creating the sheet as a parameter to createObject:

SomeItem {
id: itemId
...
submitSheetDef.createObject(itemId).open

This should add it to objects hierarchy. Maybe findChild will be able to find it after this.

Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: C++ Find Instance of Component Defenition

[ Edited ]

[Edit] Removed, not relevant to this case

 

And if that doesn't work check that you are calling these functions after the control has been added to the Scene Graph and you are searching from the correct root parent (it looks like you are though).


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: C++ Find Instance of Component Defenition

Failing that my next KB article was to be a simple debugging object you can add to a QML file that scans the Scene Graph and dumps out the hierarchy.

 

I haven't even started to write the article yet but the code is done, send me a PM if you think this would be useful and I'll send you the code.

 

Your problem might be the impetus I need to actually get it done. Smiley Happy

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: C++ Find Instance of Component Defenition

How would I go about using the findChildren() function? Something like the following?

 

QList<Sheet*> sheets = root.findChildren<Sheet*>("submitSheet");

 

_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 676
Registered: ‎05-06-2012
My Device: Dev Alpha & PlayBook
My Carrier: wifi

Re: C++ Find Instance of Component Defenition

Actually if I understand correctly the problem might be that the Sheet doesn't have a parent and is it's own root node? Thus cannot be found as a child.
_________________________________________________________
co-founder of Diaree | BB Dev for PictureThis
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: C++ Find Instance of Component Defenition

Actually further testing shows it's only delegates that act in the way I described earlier.

As long as you supply a parent within your createObj function it shows up correctly in the Scene Graph and can be found using findChild().

 

I'd assumed you'd tried zmey's suggestion and it had still failed, but did you try it?

 

Setting the parent as null would obviously not allow you to find the control under your root node.

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: C++ Find Instance of Component Defenition

Proof...

 

RecipePage {
    objectName: "The Recipe Page"

    RecipeContainer {
        objectName: "The Recipe Container"
        
        id: cont

        Label {
            objectName: "The Label"
            text: "Check the Console output for"
        }

        TextField {
             objectName: "The TextField"
             text: "Scene Graph Hierarchy"
         }

         Label {
            objectName: "The Hidden Label"
            visible: false
            text: "Can't see me!"      
          }

        attachedObjects: [
            SceneGraphScanner {
                id: scanner
                objectName: "The Scanner"
            }
        ]
    }

    attachedObjects: [
        ComponentDefinition {
            id: sheetTestCompDef
            source: "SheetTest.qml"
        }
    ]

     onCreationCompleted: {
         sheetTestCompDef.createObject(cont);
         scanner.scan();
         scanner.scanFromTop();
    }

}
"The Recipe Page [RecipePage_QMLTYPE_4]" 
"  Unknown [bb::cascades::TitleBar]" 
"  Unknown [bb::cascades::QmlComponentDefinition]" 
"    Unknown [bb::cascades::QmlDocument]" 
"  The Recipe Container [bb::cascades::Container]" 
"    Unknown [bb::cascades::ImagePaintDefinition]" 
"    The Scanner [SceneGraphScanner]" 
"    The Label [bb::cascades::Label]" 
"    The TextField [bb::cascades::TextField]" 
"    The Hidden Label [bb::cascades::Label]" 
"    Sheet Test [bb::cascades::Sheet]" 
"      Unknown [bb::cascades::QmlPage]" 
"        Unknown [bb::cascades::Container]" 
"          Unknown [bb::cascades::Label]" 
"  Unknown [QDeclarativeAbstractBoundSignal]" 

 

 


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.