04-03-2013 10:03 AM
I have a Sheet with simple actions of Cancel and Search .. when the Search option is clicked the back is going to retrieve data from a web service and then save locally .. so ..
.. when the Search action is called I set the text of a Label on the sheet to "Contacting server ..", and start an ActivityIndicator then call the network request .. when a reply is received (via a connect to a slot) in the start of the slot I set the Label's text to "Processing reply ..." and then proceed to save the local data which currently takes a while but ...
.. I never see the second change of the Label's text i.e. the "Processing reply" is never shown instead the "Contacting server .." is still visible .. so it seems the sheet/label is not being refreshed when the text changes the second time.
I've tried removing the ActivityIndicator in case that was somehow prevent the screen resfresh but that didn't help.
Anyone have any idea why the second Label.setText() is not updating on the screen? Or is there a better way to display multiple progress messages as some background work progresses? (not Toasts as they disappear to quickly unless someone's found how to extend the timeout?)
04-03-2013 12:13 PM
Not entirely sure if something could be delaying or preventing the Label from being refreshed, but are you sure that you're using the correct Label object? The same one from before and it's not out of scope? That is, is it a private member variable in your class?
04-05-2013 06:34 AM
Well I create the Label in the sheet creation method where I add it to a container in the sheet .. I then save a pointer to it as a private vaiable in my class. When another slot is then called (via a save action) I set the text there and that works fine and is displayed ok, a network request is then made and it's in the subsequent slot that's called upon network reply ready that I set the text again but that doesn't display. So I don't think it's a scope issue as otherwise the first slot that's called wouldn't work either.
But what you mentioned about something delaying the refresh made me think .. the second and subsequent time(s) I set the label is in methods which then go on to do the work and hence the same thread that would do the refresh perhaps?
If I add a toast along with the label and change it's text in the same places that I change the label these do work and show ok but I assume the toast refresh is handled by the system thread and hence not held up by the work?
If this is the case then two possible solutions I guess ..
1) In the method where I set the label text for a second time and then proceed to do work, is there any way to force a sheet gui refresh before I continue with the work?
.. or .. better option!
2) Using the toast is nicer way anyway as it displays centre screen as a message, looks better and is in a way what it was designed for .. but .. it disappears after a small time and there's no way to change that time .. what would be great would be to have toast that has similar functions to the activityindicator in that you can "open" it .. it displays .. you then then change the text which displays (currently this works) and it only disappears when you "close" it.
So it would be great to have a toast that can either set (extend) the timeout or will stay in place till it's closed.
Any thoughts on that?
04-05-2013 08:54 AM
Only thought is that the latter part of 2) sounds like a Dialog window...
04-05-2013 09:26 AM
For lengthy operations it's better to use a separate thread.
Handlers on GUI (main) thread should execute as fast as possible otherwise UI will become unresponsive. Controls can be updated only on main thread, so if you perform calculations in other threads you'll have to use some form of synchronization for passing the data back to main thread for displaying.
You can find more information here:
Signals and slots can be used for copying data across threads.