blackberry 10 - How to execute some code on UI thread -


i have worker thread (pthread) process things on background, want display result on screen. must execute code on ui thread or main thread.

in ios can use dispatch_async(dispatch_get_main_queue(), ^{ /* code */ });, in android can use view.queueevent(). can show me how same thing bb 10 native sdk?

thanks,

solution updated.

i figured out 2 methods, first simple, didn't work, don't know why. put here if wants at.

method 1.

use bps_channel_exec execute code on thread owns channel. on ui thread, create channel, set active. , on worker thread, active channel calling bps_channel_get_active, use bps_channel_exec. didn't work me, continue find reason.

method 2.

this method more complicated, simple in idea. on worker thread, push event ui thread. on ui thread main loop, add event handler process kind of event.

on worker thread: register domain calling bps_register_domain, use domain create event calling bps_event_create. next, push event active channel on ui thread calling bps_channel_push_event.

on ui thread main loop:

for (;;) {    bps_event_t *event = null;    bps_get_event(&event, -1);     if (event) {       if (bps_event_get_domain(event) == the_domain_that_is_mentioned_above) {          // handle event       }    }     ... } 

there sample here.

you should use signals , slots. event sent object executed in event loop, ergo signals sent ui objects queued , executed in ui thread.

also, should consider using qt's thread api, (see that one) make integration rest of app easier.

in experience, if worker thread need one-way (thread -> rest of app) communication, use qtconcurrent::run, if worker complex object, consider starting thread (that create , start event loop signals/slots), instantiate objects , push them worker thread. signals sent them queued , executed in new thread.

i don't remember saw advice, if specifying last argument in connect statements, wrong, @ least did. default behaviour cover 99.9% of cases. if signals block ui thread, in object-hierarchy/thread affinity wrong. , it's easy wrong.

if made ui in qml, see c++ signal qml slot in qt


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -