El mar, 03-11-2009 a las 07:39 -0800, Steve Harrington escribió:
> I am trying to use g_object_get_data() to retrieve the GtkWidget * of an 
> object.  Seems simple enough but The attached code doesn't work.  I must 
> have missed something simple but darned if I can see it.

Indeed - g_object_get_data retrieves data explicitly set on an object
with g_object_set_data. No call to the latter in your code ...

Use something like the following snippet to make it work:

> Main = GTK_WIDGET( gtk_builder_get_object(builder, "Main") );

g_object_set_data( G_OBJECT(Main),
                   "Button",
                   gtk_builder_get_object(builder, "Button") );

> gtk_builder_connect_signals( builder, NULL );
> g_object_unref( G_OBJECT(builder) );
> gtk_widget_show_all( Main );
> gtk_main( );


Another annotation just in case:

> void GTKButtonCB( GtkWidget *widget, gpointer data )
> {
> GtkWidget      *W;
> 
> 
> if( (W = g_object_get_data(G_OBJECT(Main), "Button")) != NULL )
>  {
>    GtkWidget *dialog;
>        dialog = gtk_message_dialog_new( NULL,
>                     GTK_DIALOG_DESTROY_WITH_PARENT,
>                     GTK_MESSAGE_ERROR,
>                     GTK_BUTTONS_CLOSE,
>                     "%s",
>                     "GTKButtonCB" );
>    gtk_message_dialog_format_secondary_text( GTK_MESSAGE_DIALOG(dialog),
                      "Found \"Button\" widget%s",
                      W == widget ? ", which is passed as callback
parameter"
                                  : "");

>    gtk_dialog_run( GTK_DIALOG(dialog) );
>    gtk_widget_destroy( dialog );
>  }

So in case of the example, g_object_get_data is not necessary, as the
button widget is directly available to the callback handler.

Hope the above snippets are helpful.

Happy hacking,
Florian

_______________________________________________
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