Re: How can deal with the warning?



On Sun, 2002-01-27 at 07:18, hzeng wrote:
> Hi,
>     I have just begun to study gtk.
>     I have the following warning when I use the progressbar to do some test.
>     
>         GLib-WARNING ** : g_main_interate(): main loop already active in another thread
>     
>     I search the FAQ,but don't find the answer.If I should not use the thread of c, but
What do you mean?
>     of glibc? Help, thank you very much!
>         Regards!
>     Hzeng
> --------------------------------------------------------------------------------------------
>     my programe is builded by glade, this is the callbacks.c:
>     
>         void *pbar_update(void * user_data)
>         {
>              static int i;
> 
>              while(i<=100)
>              {
>                   gtk_progress_set_value(GTK_PROGRESS(user_data),i++);
>                   while(gtk_events_pending())
>                        gtk_main_iteration();
>              }
>         }
Your mainloop will run in another thread, you shouldnt dispatch events
from it in another thread as you do here in pbar_update, and you dont
need to. Read the section about threads in the GTK FAQ. All you need to
do is:
              while(i<=100)
              {
                   
		gdk_threads_enter();
		gtk_progress_set_value(GTK_PROGRESS(user_data),i++);
                gdk_threads_leave();
              }
pluss some initalization befor you initialize gtk.(see the FAQ),
Hopefully you want to do domething else in the loop above, or else
it will progess quicker than your eye can catch..

>         void
>         on_window1_destroy                     (GtkObject       *object,
>                                                 gpointer         user_data)
>         {
>              gtk_main_quit();
>         }
> 
>         void 
>         on_window1_show          (GtkObject  *object,
>                                   gpointer user_data)
>         {
>              pthread_t thread;
>              pthread_create(&thread,NULL,pbar_update,(void *)user_data);
>         }
>     
-- 
Nils Olav Selåsdal <NOS Utel no>
System Developer, UtelSystems a/s
w w w . u t e l s y s t e m s . c o m






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