Re: Text box problems



Ok here is the problem, you were right to suggest it is with threads.  I follow

the faq regarding threads, and all it mentions are three functions,
g_thread_init, gdk_thread_[enter/leave].  Using these functions makes no
difference, here is the program if
you want to see for yourself.
/* gcc -o thread thread.c `gtk-config --cflags --libs` -lpthread
-lgthread */
#include <gtk/gtk.h>
#include <pthread.h>

static void* make_textbox( void* );
static void make_thread_box( )
{
  pthread_t thread;
  pthread_create( &thread, 0, make_textbox, 0 );
}

void * make_textbox(void * arg)
{
  GtkWidget *window, *textbox, *button, *vbox, *sw;
  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  textbox = gtk_text_new(NULL,NULL);
  button = gtk_button_new_with_label("Create Another one!");
  vbox = gtk_vbox_new(0,0);
  sw = gtk_scrolled_window_new(NULL,NULL);
  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
                                 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
  gtk_signal_connect(GTK_OBJECT(button), "clicked",
                     GTK_SIGNAL_FUNC(make_thread_box), NULL);
  gtk_text_set_editable(GTK_TEXT(textbox), TRUE);
  gtk_container_add(GTK_CONTAINER(window), vbox);
  gtk_container_add(GTK_CONTAINER(sw), textbox);
  gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, FALSE);
  gtk_box_pack_start(GTK_BOX(vbox), button, TRUE, TRUE, FALSE);
  gtk_widget_show_all(window);
  return 0;
}

gint main(gint argc, gchar *argv[])
{
  g_thread_init( NULL );
  gtk_init(&argc,&argv);
  make_textbox(NULL);
  gdk_threads_enter( );
  gtk_main();
  gdk_threads_leave( );
  return 0;
}

/* end */




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