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

Threads and input



Hi,

To start, thank you for GTK+ 2 it's a cool API !

I need to wait on message queue (IPC) so I do that in a 
dedicated thread, I want to show a dialogue box when the data is ready.
The dialog box shows but gtk_dialog_run doesn't return when I click on
button.

To clarify this I wrote a simple prog whith the same structure in
attached file.

Bye 

Stephane

/*
CC = gcc
CFLAGS =-O2 -Wall `pkg-config gtk+-2.0 gthread-2.0 --cflags --libs`
PROG = gthread

all: $(PROG)

clean:
	rm $(PROG)
*/

#include <gtk/gtk.h>

gpointer my_thread(gpointer data)
{
	gint ret;
	GtkWidget *dialogue;

	dialogue = gtk_message_dialog_new(
		NULL,
		GTK_DIALOG_MODAL,
		GTK_MESSAGE_QUESTION,
		GTK_BUTTONS_OK,
		"Message");
	
	gdk_threads_enter();
	g_print("Here !\n");
	ret = gtk_dialog_run(GTK_DIALOG(dialogue));
	gtk_widget_destroy(dialogue);
	gdk_threads_leave();

	gtk_main_quit();

	return NULL;
}

int main(int argc, char *argv[])
{
	GThread *g_thread;

	gtk_init(&argc, &argv);
	g_thread_init(NULL);
	gdk_threads_init();

	g_thread = g_thread_create(my_thread, 
				   NULL,
				   TRUE, 
				   NULL);
	
	gdk_threads_enter();
	gtk_main();
	gdk_threads_leave();

	g_thread_join(g_thread);

	return 0;
}


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