Re: gdk_threads_leave is possible to cause segmentation fault?





In gdk manual i see thath gdk_threads_enter and leave has been
deprecated and alll gdk and gtk+ calls should be made from main thread.
How we do this? Someone have any example?

You have to call g_idle_add (that is thread safe) every time you need to
update one or more widgets from an external thread.

Let's think about a common situation, for instance you are encoding a video
file and you want to update a progress bar:

[from encoding thread]
struct progress {
    char label[50];
    float value;
};

myprg = malloc(sizeof(struct progress));
myprg->value = 75.0;
strncpy(myprg->label, "Second pass", sizeof(myprg->label));
g_idle_add((GCallback)progress_update, myprg);

gboolean progress_update(struct progress *p);
{
     gtk_progress_bar_set_text(p->label);
     gtk_progress_bar_set_fraction(p->value);
     free(p);
     return FALSE; // it means that you want to run this only once
}

-- 
*Bye,*
* Gabry*


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