0
votes

I am having troubles upon runtime in codeblocks. It says “(HelloWorld.exe:3312): libglade-CRITICAL **: glade_xml_relative_file: assertion `filename != NULL’ failed”

I am using Glade, and GTK at the same time to build a UI for my project, but I've been working on it for days and I still couldn't figure out what's wrong? Thank you.

int main(int argc, char *argv[])
{
     gtk_init(&argc, &argv);

     /*import glade file*/
     xml = glade_xml_new("hello.glade", NULL, NULL);

     /* get a widget (useful if you want to change something) */
     widget = glade_xml_get_widget(xml, "mainWindow");

     /* connect signal handlers */
     glade_xml_signal_autoconnect(xml);

     /*show widget*/
     gtk_widget_show (widget);

     gtk_main();

     return 0;
}

It builds fine, it just won't run when I try to run it.

1
You sure the file exists?avmohan
From the error, the reason may be that you are not pasing the file name in proper format. After parsing for filename the filename becomes NULL, that is why assertion fails.Don't You Worry Child
@v3ga yes, it is on the same folder as my projectberdi9
@MadHatter it is really hello.glade , it is on the same folder as my project, as I mentioned aboveberdi9
Try mentioning complete path, right from / if in linux or from X: if on windowsDon't You Worry Child

1 Answers

1
votes

There are basically two formats of a glade file: 1:libglade , 2:gtkBuilder.

I have also faced the same problem when i was working on my summer project. instead of building your glade file using glade_xml_new() use gtk_builder_new() because i think your glade file if of gtkBuilder type.

sample program:

 int main(int argc, char *argv[])
{
    GtkBuilder *gtkBuilder; 
    GtkWidget  *window;

    gtk_init(&argc, &argv);
    gtkBuilder = gtk_builder_new(); 

    gtk_builder_add_from_file(gtkBuilder, "name of your glade file", NULL);/*this api is used to                                                  
                               build the glade file which is created by using glade(glade3) UI designer.*/


    window = GTK_WIDGET( gtk_builder_get_object( gtkBuilder, "name of your window") );


    gtk_builder_connect_signals( gtkBuilder, NULL ); /*connecting signals so that appropriate   
                                       handler can be called to handle the button clicked event*/
    g_object_unref(G_OBJECT(gtkBuilder));
    gtk_widget_show(window);
    gtk_main(); /*it is basically a loop to make window appear. if we not write it then window                    
                 will appear but disappear after few seconds automatically.*/
    return 0;
}

the sample program is not complete it is only to understand the right way to build glade file for complete program and for more info on how to program in c using gtk libraries to build GUI's you can refer http://programming-simplified.blogspot.com