Welcome, Guest

Author Topic: Gtk-CRITICAL **: gtk_widget_show: assertion `GTK_IS_WIDGET (widget)` failed  (Read 245 times)

Faruk

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
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.
« Last Edit: February 12, 2019, 06:54:13 AM by Faruk »

Faruk

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
Re: GTK and glade does not run together (signal SIGSEGV problem)
« Reply #1 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.
« Last Edit: February 11, 2019, 03:15:18 PM by Faruk »

Faruk

  • Newbie
  • *
  • Posts: 30
  • Karma: +0/-0
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.