Buggy example code in GtkFileSelector



Hi everyone,

In the example 1. in the file http://developer.gnome.org/doc/API/2.0/gtk/GtkFileSelection.html
You have that function :

void store_filename (GtkFileSelection *file_selector, gpointer user_data) {
   const gchar *selected_filename;

   selected_filename = gtk_file_selection_get_filename (GTK_FILE_SELECTION (file_selector));
   g_print ("Selected filename: s\n", selected_filename);
}

which is attached to a callback finction like that :

g_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (file_selector)->ok_button),
                  "clicked",
                  G_CALLBACK (store_filename),
                  NULL);

First, it won't compile since there is a '%' missing for the '%s' in g_print(...).
And once this is corrected, you have, at runtime:

(scriptMaker:11305): GLib-GObject-WARNING **: invalid cast from `GtkButton' to `GtkFileSelection'

(scriptMaker:11305): Gtk-CRITICAL **: file gtkfilesel.c: line 1217 (gtk_file_selection_get_filename): assertion `GTK_IS_FILE_SELECTION (filesel)' failed

I workd better with that protype:

void store_filename (GtkButton *button, gpointer user_data)

and connected like that :

g_signal_connect_swapped (GTK_OBJECT (GTK_FILE_SELECTION (file_selector)->ok_button),
		          "clicked",
			  G_CALLBACK (gtk_widget_destroy), 
			  (gpointer) file_selector); 


Anyway, the Gtk+ doc is really a great job, go on like that !

Adrien Beaucreux

-- 
informancer afturgurluk org
c00kM4st4 afturgurluk org
--
Quand une mouche se pose sur un plafond,
fait-elle un demi-tonneau ou un demi-looping ?



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