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
lvandyk
Posts: 19
Registered: ‎07-17-2012
My Device: BB 10 Alpha Device
My Carrier: Vodacom
Accepted Solution

QML pauses while waiting for thread.

I have a login screen that when the LOGIN button is pressed, I want the buttons to dissapear and a progress bar to display.

 

My code when LOGIN is pressed:

 

Set the button visible property to false and progress bar visibility to true.

Create a thread and connect to my web service and get response.

Wait for thread to finish with pthread_join()

Handle the response and either make the button visible again or go to another part of application.

 

 

The problem is the button does not dissappear nor does the progress bar appear. They only do AFTER the pthread_join().

 

Any suggestions on what I can do to fix this? I just want to prevent the user from spamming the login button while it checks the login details.

 

Thanks!

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: QML pauses while waiting for thread.

UI updates won't happen since you blocked the UI thread with pthread_join().

I did something very similar in the HelloCamera sample:

https://github.com/blackberry/Cascades-Community-Samples/tree/master/HelloCamera

 

When the user presses the "Take Photo" button, I gray it out and start my worker threads (hidden away inside camera_take_photo() implementation).   When one of my threads indicates completion, I emit a SIGNAL which is caught by a SLOT function in my app that makes the button visible again.

 

I suggest that your button handler marks itself invisible or disabled, spawns a thread and does not join that thread.

Instead, when that thread completes, it should emit a SIGNAL.  Then your app has a handler SLOT bound to that signal which makes the button visible again and joins your thread.

 

In short.. SIGNALS and SLOTS is your solution.

 

Cheers,

Sean

 

Please use plain text.
Contributor
lvandyk
Posts: 19
Registered: ‎07-17-2012
My Device: BB 10 Alpha Device
My Carrier: Vodacom

Re: QML pauses while waiting for thread.

Awesome! I thought it would be the UI thread getting blocked.

Thank you very much for the help!
Please use plain text.