Re: How can deal with the warning?
- From: James Henstridge <james daa com au>
- To: hzeng <hzeng hf tvia com>
- Cc: gtk-devel-list gnome org
- Subject: Re: How can deal with the warning?
- Date: Sun, 27 Jan 2002 16:39:12 +0800
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
of glibc? Help, thank you very much!
This list is for development of the gtk library itself, rather than
development with gtk. You should read the section of the gtk tutorial
on writing threaded applications, as it will explain most of the
problems you are having. I will give a few tips below.
First of all, if you are writing a multithreaded application, you must
call g_thread_init() before calling gtk_init().
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();
}
}
As this function is occuring in a different thread, the gtk calls must
be protected by gdk_threads_enter() and gdk_threads_leave() calls. It
should not be necessary to iterate the main loop here. Your code should
look something like:
while (i <= 100) {
gdk_threads_enter();
gtk_progress_set_value(GTK_PROGRESS(user_data), i++);
gdk_threads_leave();
}
The main thread will take care of updating the display to the new
progress value.
James.
--
Email: james daa com au
WWW: http://www.daa.com.au/~james/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]