I am new to this glade thing (and also to this forum), and would like to know if any of you guys could help me out:
I have to get the filename the user selects from the chooserbutton and send it as a string to a function. Unfortunately, I've been receiving this annoying error:
Gtk-CRITICAL **: IA__gtk_file_chooser_get_uri: assertion `GTK_IS_FILE_CHOOSER (chooser)' failed
I thought it was due to the wrong use of the widget. Could somebody help me to figure this out? The source code is below, and as you can see, it's from a Glade-GTK tutorial found at https://live.gnome.org/Glade/Tutorials.
The program is a simple 2 button window: first button is the filechooserbutton, and the second is the standard button that calls the "clica" function when clicked. It should display the filename selected by the user through the file chooser button, but that is when the error happens.
Test source (just to figure out how to use the widget):
#include <gtk/gtk.h>
int
main( int argc,
char **argv )
{
GtkBuilder *builder;
GtkWidget *window;
GError *error = NULL;
/* Init GTK+ */
gtk_init( &argc, &argv );
/* Create new GtkBuilder object */
builder = gtk_builder_new();
/* Load UI from file. If error occurs, report it and quit application.
* Replace "tut.glade" with your saved project. */
if( ! gtk_builder_add_from_file( builder, "tut.glade", &error ) )
{
g_warning( "%s", error->message );
g_free( error );
return( 1 );
}
/* Get main window pointer from UI */
window = GTK_WIDGET( gtk_builder_get_object( builder, "window1" ) );
/* Connect signals */
gtk_builder_connect_signals( builder, NULL );
/* Destroy builder, since we don't need it anymore */
g_object_unref( G_OBJECT( builder ) );
/* Show window. All other widgets are automatically shown by GtkBuilder */
gtk_widget_show( window );
/* Start main loop */
gtk_main();
return( 0 );
}
void clica(GtkFileChooser *filechooserbutton1){//this button was inserted through Glade
char cNome[250];
*cNome = gtk_file_chooser_get_uri(GTK_FILE_CHOOSER(filechooserbutton1));
printf("\n%s", cNome);
}
Glade file:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.24"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkFileChooserButton" id="filechooserbutton1">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">button</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="clica" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
04/01/2013 UPDATE (now we have the glade file)
We can now see that you used the signal of the wrong object. You connected your "clica" callback to the "clicked" signal of the GtkButton "button1", instead of connecting it to the GtkFileChooserButton "filechooserbutton1".
Original answer: Without the glade file, we can't see which signals you connected, not to what they are connected. But chances are here that you're not following the prototype of the signal. If the assertion fails, that means that in your callback, you that first argument you think is a GtkFileChooser is something else.