|
|
发表于 2006-1-18 09:42:41
|
显示全部楼层
Post by dyte200
你的编译参数是什么?
gcc -o test test.c `pkg-config gtk+-2.0 gthread-2.0 --libs --cflags`
你贴出源代码或许有帮助。
13楼提到的gdk_flush()好像对entry没什么作用,用在label上倒可以,也许我不知道entry上怎么用 :confused: ,13楼提到方法是:
gtk_entry_set_text()
gdk_window_process_updates () 或 gdk_window_process_all_updates ()
gdk_flush ()
附上我的一个实例
[PHP]
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <pthread.h>
GtkWidget *win,*entry;
int i;
gchar str[255];
guint timer;
void *updata(void *args)
{
while (1) {
sleep(1);
if (i < 10) ++i; else i = 0;
sprintf (str,"n: %d",i);
gdk_threads_enter();
gtk_entry_set_text (GTK_ENTRY(entry),str);
gdk_threads_leave();
}
}
int main (int argc,char *argv[]) {
pthread_t tid;
g_thread_init (NULL);
gdk_threads_init ();
gtk_init (&argc,&argv);
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(G_OBJECT(win),"delete_event",
G_CALLBACK(gtk_main_quit),NULL);
entry = gtk_entry_new();
gtk_container_add (GTK_CONTAINER(win),entry);
gtk_widget_show (entry);
gtk_widget_show (win);
gtk_entry_set_text (GTK_ENTRY(entry),"hello world");
i = 0;
pthread_create (&tid, NULL, updata,NULL);
/* enter the GTK main loop */
gdk_threads_enter ();
gtk_main ();
gdk_threads_leave ();
return 0;
}
[/PHP] |
|