Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A13 => Topic started by: Faruk on February 11, 2019, 11:03:01 AM

Title: Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)` failed
Post by: Faruk on February 11, 2019, 11:03:01 AM
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
Code: [Select]
program recived signal SIGSEGV, segmentation fault error every time. I did debug and error return on
Code: [Select]
gtk_widget_show(window) line. I took same error other my code experiments. I struggle with this error since 3 days. My code this:


Code: [Select]
#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.
Title: Re: GTK and glade does not run together (signal SIGSEGV problem)
Post by: Faruk on February 11, 2019, 02:57:45 PM
I regulated on my code. New code this:

Code: [Select]
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
Code: [Select]
program received signal SIGSEGV, segmentation faul error. Now I encounter new error. Program return
Code: [Select]
Unable to file object with id window writing. Other name of this error
Code: [Select]
Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)` failed. How can I fix this?? Thanks.
Title: Re: Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)` failed
Post by: Faruk on February 20, 2019, 12:40:37 PM
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.