On 9/11/07, Brian Hartman <[EMAIL PROTECTED]> wrote:
> Hi Everyone.
>
> I'm trying to write a simple program that changes a label when a button is
> clicked.  The program compiles and runs, but there's no label change.
> Here's what I have in my callbacks.c:
>
> #ifdef HAVE_CONFIG_H
> #  include <config.h>
> #endif
>
> #include <gtk/gtk.h>
>
> #include "callbacks.h"
> #include "interface.h"
> #include "support.h"
>
>
> void
> on_window1_destroy                     (GtkObject       *object,
>                                         gpointer         user_data)
> {
> gtk_exit(0);
> }
>
>
> void
> on_button2_clicked                     (GtkButton       *button,
>                                         gpointer         user_data)
> {
> gtk_exit(0);
> }
>
>
> void
> on_button1_clicked                     (GtkButton       *button,
>                                         gpointer         user_data)
> {
> GtkWidget* window1;
> GtkWidget* window2;
> GtkWidget* label1;
> gtk_label_set_text((label1),"Hi!");
> }
>
> Like I said, this runs w/o any compile errors, but when I run it in the
> terminal, I see the following:
>
> Gtk-CRITICAL **: gtk_label_set_text: assertion `GTK_IS_LABEL (label)' failed
>
> So something went wrong.  Can anyone help me out here?

I don't see any statement between these two lines that actually
initializes label1 to point to a widget:

GtkWidget* label1;
gtk_label_set_text((label1),"Hi!");

For some examples of how to write something similar, please look at
the gtk-demo program that should be on your box as a part of your gtk
install.

You reference "callbacks.c", hinting that you're using glade with code
generation - don't do that, it's deprecated.

Also, when you compile, it sometimes helps to have the -Wall flag
(enable all warnings), so you can catch problems like this (with
-Wall, gcc will tell you that you are attempting to use label1 without
initializing it).

-Jim
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to