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



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/

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



On 28/06/2007 20:11, Bartosz Kostrzewa wrote:
> Hi,
>
> I'm sure this question has been asked at least a million times but I
> couldn't deduce the solution to it from any of the documents I've found.
>
> I have an iconview which is populated with hundreds of thumbnails which
>  takes a lot of time so I wanted to do it in a separate thread. However,
> the iconview ends up with one element and segfaults if I click anywhere
> outside of that one element.
>
> I can access the elements of the treemodel just fine even while the
> populate thread is doing its job.
>
> Are there any docs on doing something similar? Or perhaps a gtkmm app
> that does something like that?
>
> In the constructor of the widget holding the iconview I do the following:
>
> Glib::Thread* const thread = Glib::Thread::create(
> 	sigc::mem_fun(*this,&CPrintPreviewWidget::populate_iconview),
> 	false);
>
> and populate_iconview looks like so:
>
> void CPrintPreviewWidget::populate_iconview(void)
> {
> 	std::list<Glib::ustring>::iterator f_iterator =
> 		image_filelist.begin();
>
> 	std::list<Glib::ustring>::iterator f_end = image_filelist.end();
> 	
> 	Gtk::TreeModel::iterator iter;
> 	Gtk::TreeModel::Row row;
> 	
> 	while( f_iterator != f_end )
> 		{
> 		iter = refImageList->append();
> 		row = *iter;
> 		
> 		row[ ImageListColumns.filenames_column ] =
> 			Glib::path_get_basename( *f_iterator );
> 		
> 		row[ ImageListColumns.thumbnails_column ] =
> 			Gdk::Pixbuf::create_from_file( *f_iterator,
> 			 72,
> 			 72 );
> 		
> 		std::cout << "populating: " << *f_iterator << std::endl;
> 			
> 		f_iterator++;
> 		}
> 	}
> _______________________________________________
> gtkmm-list mailing list
> gtkmm-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
>
>   




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