|
在学习《GTK+/GNOME程序设计》中,遇到例程labelsample
编译后运行是按按钮时终端内显示
(lablesample:25908): GLib-GObject-CRITICAL **: g_signal_connect_closure_by_id: assertion `signal_id > 0' failed
且Lable不变
我认为该程序是应该能够通过按钮改变label的内容的
请高人指点一二,多谢了
编程环境:FreeBSD 7.2R
源程序如下
#include <gtk/gtk.h>
void CloseTheApp(GtkWidget *window,gpointer data)
{
gtk_main_quit();
}
void ChangeText(GtkButton *button,gpointer data)
{
static gboolean textType =TRUE;
if(textType)
gtk_label_set_text(GTK_LABEL(data),"Some Text");
else
gtk_label_set_text(GTK_LABEL(data),"More Text");
textType=!textType;
}
gint main(gint argc,gchar *argv[])
{
GtkWidget *window;
GtkWidget *label;
GtkWidget *mainbox;
GtkWidget *button;
gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window),320,200);
gtk_window_set_title(GTK_WINDOW(window),"Label Sample");
gtk_container_set_border_width(GTK_CONTAINER(window),10);
gtk_signal_connect(GTK_OBJECT(window),"destroy",
GTK_SIGNAL_FUNC(CloseTheApp),NULL);
mainbox=gtk_vbox_new(FALSE,5);
label=gtk_label_new("A Label");
gtk_box_pack_start(GTK_BOX(mainbox),label,TRUE,TRUE,5);
button=gtk_button_new_with_label("Change Text");
gtk_box_pack_end(GTK_BOX(mainbox),button,TRUE,TRUE,5);
gtk_signal_connect(GTK_OBJECT(button),"Clicked",
GTK_SIGNAL_FUNC(ChangeText),label);
gtk_container_add(GTK_CONTAINER(window),mainbox);
gtk_widget_show_all(window);
gtk_main();
return 0;
} |
|