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



I'm taking the liberty of forwarding Klaus' reply to preserve it for
posterity, it was most helpful! Hope that's ok with you.

Danke Klaus!

I've almost got it to work. Now I just need to bite through the mutex
thing and I'm good to go as right now I get a segfault and not all
thumbnails are loaded properly.

Impressively, the code is only about 300 lines which says something very
good about gtkmm :)

When I'm done with this I'll try to produce an example on how to
populate an iconview in a separate thread because what I got turns out
to be quite general.

>> What a shame, so I actually need to understand the dispatcher example
>> > fully... was hoping there'd be an easy solution to this  :) 
>> >
>> >   
> 
> There might be an easier way, but my way you could use a class like this:
> 
> 
> class ThreadThumbs : public sigc::trackable
> {
> public:
>   virtual ~ThreadThumbs();
> 
>   void launch();
>   void join();
> 
>   Glib::Dispatcher& signal_new_thumbs_ready(); // connect add thumbs
> function
>  
>   _PointerToPixbuf_ get_next_thumb_(); // use mutex, return 0 when queue
> empty
> 
> private:
>   Glib::Thread*       thread_;
>   Glib::Dispatcher    signal_new_thumbs_ready_;
> 
>   void add_thumb_to_view();
>   void thread_function_create_thumbs(); // create thumbs , add to queue
> (mutex), call signal_new_thumbs_ready_.emit()
>  
>   GLib::Mutex thumbs_mutex_
>   std::queue<_PointerToPixbuf_> thumbs_
> };
> 
> 
> Just add an instance to your widget class and the dispatcher will
> automatically integrate with your GUI thread.
> 
> Regards,
> Klaus
> 







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