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
j2theowens
Posts: 15
Registered: ‎07-15-2013
My Device: Blackberry Z10
My Carrier: Verizon
Accepted Solution

What is the best way to refresh a Page when its UI elements are updated?

I have a Page within a NavigationPane. I click a button that is immediately disabled while I perform some behind the "scenes" (a little BB humor) logic. After I'm done, I want to re-enable the button.  I've found how I can edit the attributes through code, but the screens stays the same.

 

Basically I have the same problem as this guy:

 

http://stackoverflow.com/questions/12482464/cannot-access-qml-object-in-c-code

 

Do I have to store a pointer to the application object and continually call setScene? Do I always have to set the scene to the Navigation pane since that's what I"m pushing my pages onto? 

 

Is there a cleaner way to do this?

 

Thanks again, guys.

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: What is the best way to refresh a Page when its UI elements are updated?

If you're changing the enabled property of the object, I would think you'd need to also emit the enabledChanged signal for that object afterwards. Have you tried that already? (It's possible it's emitted automatically, but I can't think of any other reason why the rendering thread wouldn't update to reflect the change... this stuff is supposed to just happen so there's never any "refresh" action needed on your part.)

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Contributor
j2theowens
Posts: 15
Registered: ‎07-15-2013
My Device: Blackberry Z10
My Carrier: Verizon

Re: What is the best way to refresh a Page when its UI elements are updated?

[ Edited ]

Okay, that sounds more like the real solution. How would I emit such as signal?

 

I'm from an Android background and it was generally automatic. Could you show me a snippet of code?

 

 

Here's some of the code I'm using:

 

 

Getting button:

signInButton = getOwnedPage()->findChild<Button*>(SIGN_IN_BUTTON_OBJECT_NAME);

 

Later on...

 

signInButton->setEnabled(true);

signInButton->setProperty("text", "wutwut");

qDebug() << signInButton->text();

signInButton->setText("hey now");

qDebug() << signInButton->text();

 

I have the debugs to prove that I'm actually changing the properties of that object, but it's still not reflected on the screen.

Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: What is the best way to refresh a Page when its UI elements are updated?

Example from real code, look for the emit statements in https://github.com/seanmcveigh/ScreenSize/blob/master/ScreenSize.cpp and the class definition in the matching header file, where the properties were defined along with NOTIFY signals named using the standard convention (i.e. propertyName+"Changed").

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Please use plain text.
Contributor
j2theowens
Posts: 15
Registered: ‎07-15-2013
My Device: Blackberry Z10
My Carrier: Verizon

Re: What is the best way to refresh a Page when its UI elements are updated?

Thanks for the information.

 

I tried typing out what I thought should happen, but then I realized I still don't know exactly how it's supposed to work.

 

Here is my best attempt:

 

I would have my class extend QObject so I could use signals and slots.

I would then list a boolean property right under that Q_OBJECT macro. (let's call it signInState)

I would then make a public signal called signInEnabled(boolean signInState).

I would then connect my class with signal to the button with setEnabled(bool) slot.

 

Is that correct? Do I need to do anything with property aliases?

 

That sure is a mouthful of code for one thing. I'm eager to see if it helps or hinders the overall structure of the project.

Please use plain text.
Contributor
j2theowens
Posts: 15
Registered: ‎07-15-2013
My Device: Blackberry Z10
My Carrier: Verizon

Re: What is the best way to refresh a Page when its UI elements are updated?

It works now! 

 

Thanks for the help, I'm one step closer to understanding the signals and slots system.

Please use plain text.