Re: Non-Blocking GUI developement



On 1/27/07, Melvin Newman <zexelon gmail com> wrote:
I am now trying to use g_idle_add(), however I cant seem to figure out how
to pass data into the function that g_idle_add calls.

    g_idle_add(update_server_version,data.data);

above is the call I am making, data.data is defined as char * and no mater
what i do, the string gets completely corrupted when it gets passed into the
function.

I expect the string is being freed or deallocated somehow before the
main thread sees it. Try something like:

In the worker thread context:

 for(;;) {
    char *data = g_malloc( lots of stuff );

    fill_with_information( data );
    g_idle_add( update_gui, data );
 }

update_gui will run in the main thread context and can make GUI calls:

 gboolean update_gui( char *data )
 {
   // this llooks through data and pdates the GUI
   update_display( data );

   g_free( data );
   // returning FALSE removes this idle handler
   return( FALSE );
 }

I guess you might want to limit the number of update-gui()s that can
queue up, but that's a fine-tuning thing.

John



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