07-17-2012 10:30 AM
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.
Solved! Go to Solution.
07-17-2012 11:32 AM
UI updates won't happen since you blocked the UI thread with pthread_join().
I did something very similar in the HelloCamera sample:
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.