Re: [gtk-list] Why doesn't it work ??



1) Your callback for the toggled signal is of the wrong function
prototype.
"toggled"   void        user_function      (GtkToggleButton *togglebutton,
                                            gpointer user_data);
So, get rid of the GdkEvent* parameter, as it's not used by this type
of signal handler.

2)You are connecting  cb_toggle()
before label has been created. So, you are not passing
what you think you're passing. You shouldn't connect
the signal until the label is created.

Hope that helps.
Donna

----- Original Message -----
From: B Mohrgan Pratten <mohrgan@sympatico.ca>
To: <gtk-list@redhat.com>
Sent: Wednesday, March 15, 2000 6:03 PM
Subject: [gtk-list] Why doesn't it work ??


> I am vary new to gtk, but like what I have seen,.
>
> I have a question with source code.  >

----------------------------------------------------------------------------
----


> #include <gtk/gtk.h>
>
> void cb_toggle (GtkWidget*, GdkEvent*, GtkWidget*);
> void cb_exit (GtkWidget*, GdkEvent*, gpointer);
> int main (int, char**);
>
> void cb_toggle (widget, event, label)
> GtkWidget *widget;
> GdkEvent *event;
> GtkWidget *label;
> {
> gtk_label_set_text (GTK_LABEL (label), "DOWN");
> }
>
> void cb_exit (widget, event, data)
> GtkWidget *widget;
> GdkEvent *event;
> gpointer data;
> {
> gtk_main_quit ();
> }
>
> int main (num, str)
> int num;
> char **str;
> {
> GtkWidget *window;
> GtkWidget *toggle;
> GtkWidget *label;
>
> gtk_init (&num, &str);
>
> window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
> gtk_signal_connect (GTK_OBJECT (window), "delete_event",
> GTK_SIGNAL_FUNC (cb_exit), NULL);
>
> toggle = gtk_toggle_button_new ();
> gtk_container_add (GTK_CONTAINER (window), toggle);
> gtk_signal_connect (GTK_OBJECT (toggle), "toggled",
> GTK_SIGNAL_FUNC (cb_toggle), label);
> gtk_widget_show (toggle);
>
> label = gtk_label_new ("UP");
> gtk_container_add (GTK_CONTAINER (toggle), label);
> gtk_widget_show (label);
>
> gtk_widget_show (window);
>
> gtk_main ();
>
> return (0);
> }
>
>
>
>


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