Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)` failed

Started by Faruk, February 11, 2019, 11:03:01 AM

Previous topic - Next topic

Faruk

Hello. I work for on GUI app on my olimex A13 development kit with codeblocks. I created interface on glade and I tried run glade with gtk-3.0 on codeblocks but I took program recived signal SIGSEGV, segmentation fault error every time. I did debug and error return on gtk_widget_show(window) line. I took same error other my code experiments. I struggle with this error since 3 days. My code this:


#include <stdlib.h>
#include <gtk/gtk.h>

int main(int argc, char *argv[])
{
GtkBuilder *builder;
GtkWidget *window;
GError *err = NULL;

gtk_init(&argc, &argv);

builder=gtk_builder_new();
gtk_builder_add_from_file(builder, "/home/olimex/Desktop/New1/box_test/GUI.glade", NULL);


//window=GTK_WIDGET(gtk_builder_get_object(builder,"GUI"));
if (NULL==window)
{
    fprintf(stderr, "Unable to file object with id \"GUI\" \n");
}
gtk_builder_connect_signals(builder, NULL);

g_object_unref(builder);

gtk_widget_show(window);
gtk_main();

}

void on_window_main_destroy()
{
gtk_main_quit();
}


How can I fix this error? Thanks.

Faruk

I regulated on my code. New code this:

int main(int argc, char *argv[])
{
    GtkBuilder *builder;
    GtkWidget *window;
    GError *err = NULL;

    gtk_init(&argc, &argv);

    builder=gtk_builder_new();
    gtk_builder_add_from_file(builder,"/home/olimex/Desktop/New1/box_test/GUI.glade",NULL);

    if(err != NULL)
    {
        fprintf(stderr,"Unable to read file: %s\n", err->message);
        g_error_free(err);
        return 1;
    }


    window=GTK_WIDGET(gtk_builder_get_object(builder,"GUI"));
    if (NULL==window/*0==gtk_builder_add_from_file(builder, "/home/olimex/Desktop/New1/box_test/builder.ui",&err)*/)
    {
        fprintf(stderr, "Unable to file object with id \"window\" \n");
        //g_printerr("Error loading file: %s\n", err->message);
        //g_clear_error(&err);
        return 1;
    }
    gtk_builder_connect_signals(builder, NULL);



    g_object_unref(builder);

    gtk_widget_show(window);
    gtk_main();

    return 0;

}

void on_window_main_destroy(GtkWidget *widget, gpointer user_data)
{
    gtk_main_quit();
}


and I exceed program received signal SIGSEGV, segmentation faul error. Now I encounter new error. Program return Unable to file object with id window writing. Other name of this error Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)` failed. How can I fix this?? Thanks.

Faruk

Cause of problem: name of glade object and name of GTK object (for use the object) different. For example: name of label object is "label1" in glade and name of label object in GTK is "label". So GTK does not find "label" in glade file and return this error.