Re: Updating the contents of a treemodel from another thread.



Niko Demmel wrote:
> Hi Bartosz,
> 
> You probably want to use Glib::Mutex, Glib::Mutex::Lock and/or
> Glib::Dispatcher to make sure that only one thread accesses the iconview
> at a time.

> Maybe have a look at the thread examples:
> 
> http://www.gtkmm.org/docs/glibmm-2.4/examples/thread/

I have, i get the general concept but couldn't quite figure out yet how
to integrate this into a gui app. Well, I guess I'll have to stare at
the examples some more.

> 
> My first idea would be either:
> Lock the access to the inconview with a mutex and let the worker thread
> add the thumbs directly. But that way you will use the mutex whenever
> you access the iconview, even if the worker thread is long finished.
> Or maybe better: Use a queue and a mutex for it. Let the worker thread 
> add the thumbs to the queue (with some id) and inform the main thread
> with a Glib::Dispatcher whenever a (2,3,...) thumbnail is ready so
> that it would add it to the iconview. This way the worker thread does
> not need to concern itself with the iconview.
> 
> Just some thoughts,
> Klaus
> 

Ah, I haven't thought of it this way. So basically I would create the
pixbuf in the thread and only then make the main loop (via a signal
emitted through the dispatcher) add the next row to the model using that
pixbuf.

What a shame, so I actually need to understand the dispatcher example
fully... was hoping there'd be an easy solution to this :)

Thanks!

-Bartek




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]