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
trivedirujuta
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition

Re: settext doesnt work when label is in second page of navigation pane

NavigationPane {id:nav
   Page1{}
   attachedObjects:[
       Page2{
           id:page2
           objectName:"page2"
       }
   ]
   }

 Above is main.qml

 

Page {
   
    property alias pagetxt:lbl.text
    Container {
        Label{
            id:lbl
            objectName:"lbl"
          //  text:"lbl"
            onTextChanged:{}
        }
    }
   }

 PAge2

 

And below is cpp code

 root = qml->createRootObject<NavigationPane>();
 page2 = root->findChild<Page*>("page2");

 lbl = root->findChild<Label*>("lbl");
 lbl->setText("set text from here");
 
page2->setProperty("pagetxt","set text from property");
qDebug()<<"got text?????"<<lbl->text();

 I got text "set text from here" in console

Rujuta Trivedi
Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: settext doesnt work when label is in second page of navigation pane

Was it wrapped around an error or warning message?

 

Have you defined lbl as Label* lbl?

 

Does lbl = page2->findChild() return a valid object?

 


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

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

Re: settext doesnt work when label is in second page of navigation pane

Try changing this,

 

 lbl = root->findChild<Label*>("lbl");

 

to this,

 

 lbl = page2->findChild<Label*>("lbl");


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
trivedirujuta
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition

Re: settext doesnt work when label is in second page of navigation pane

changed it. It returns value set by setproperty in console but doesnt update UI

Rujuta Trivedi
Developer
BBSJdev
Posts: 6,118
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30

Re: settext doesnt work when label is in second page of navigation pane

Debugging by forum is absolutely a nightmare.

 

I don't have the time right now to write an example so either learn how to debug your own code or wait for someone to write an answer for you.

 

 


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

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: settext doesnt work when label is in second page of navigation pane

Hi,

If findChild returns a non-NULL value, make sure you aren't instantiating the pane twice and modifying a second copy.

If you post a complete code (full QML-s + relevant C++ file) we may be able to spot the error.

Andrey Fidrya, @zmeyc on twitter
Developer
trivedirujuta
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition

Re: settext doesnt work when label is in second page of navigation pane

[ Edited ]

@BBSJDev thank u for helping me so far.Actually I'm not able to find anything while debugging,everything is initializing,using properly,lbl returns text it just doesn;t display on UI.

@Zmey Here is the total project. Please guide me to solve

Rujuta Trivedi
Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: settext doesnt work when label is in second page of navigation pane

1) In main.qml two pages are created: Page1 and Page2 (with id 'page2').

2) In applicationui.cpp you set the text on Page2 (with id 'page2').

3) When the button is pressed on Page1, another instance of Page2 is created (with id 'page1') and pushed into NavigationPane. This second copy of Page2 doesn't have any text set.

The first instance ('page2') is never displayed.

A possible way to fix this:

1) Remove attachedObjects: [ Page2 ... in main.qml

2) After creating the page from ComponentDefinition, call a helper function in C++ to set the text. Pass the page as a parameter to this function.

Note that you can't do this in applicationui.cpp because the page will not exist at this step.

Andrey Fidrya, @zmeyc on twitter
Developer
trivedirujuta
Posts: 528
Registered: ‎10-06-2009
My Device: 9800,BB Dev Alpha,z10 limited edition

Re: settext doesnt work when label is in second page of navigation pane

Thanks a lot Zmey. How can I pass the page object to c++ method?

 

onClicked:{

                var page = page1.createObject();

               _app.callmethod(page)

                nav.push(page)

            }

 

Is it right?

 

it gives error  Error: Unknown method parameter type: Page* 

Rujuta Trivedi
Developer
Zmey
Posts: 1,514
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: settext doesnt work when label is in second page of navigation pane

That's correct. You'll also need to make the corresponding changes in .h:

 

    void callmethod(bb::cascades::Page *page);

And .cpp:

 

void ApplicationUI::callmethod(Page *page){
  Label *myLabel = page->findChild<Label *>("lbl");
  myLabel->setText("hyihh2");
}

I've changed Label declaration to be local. Member variable is not required.

 


Andrey Fidrya, @zmeyc on twitter