Re: GtkTree and GtkThread: update and refresh



On 09/21/2011 10:53 PM, Paolo wrote:
Hi! I have a problem about the update and refresh of a tree. This is the
situation: I have a populated tree and a button that update the tree. The
button's event calls a function that permorfs the following things:
1) Reset the treemodel appending a single text row "Loading"
2) Execute a db query
3) Reset the treemodel appending the results of the query
No errors, but a refresh problem. I can't see the text row "Loading" (1st
step); I can just see the new populated tree (3th step).

I could put the following code between the step 1 and 2:

           while(gtk_events_pending())
               gtk_main_iteration();

or start step 2 from an idle callback, use g_idle_add_full() to register a function that will call step 2.

This solution works but it blocks the whole GUI.
A thread can help me for the GUI block and the pending events, but I have
another problem: after several clicks of the button the program blocks. I
don't know what happen: no errors, no segmentation fault.

Is it correct create a thread for each event of the button in that way?

             g_thread_create((GThreadFunc) loading_tree_and_the_fill_tree,
NULL, FALSE,&err)

as suggested elsewhere read about gtk and threads. GTK calls should be made from the main thread, so do your db query in a thread, load the results in a datastructure, use g_idle_add() again to register a function that will be called from the mean thread and in *that* function load the data in the treemodel.

Olivier



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