I start working with Gtk +, I follow this guide on how to make the first application, but when I try to run the executable, I get this error:
Gtk-Critical **: gtk_widget_show assertion GTK_IS_WIDGET(WIDGET)
I see a lot of people on the google with the same error, but I donβt see the answer how to fix it.
My C code:
#include <stdlib.h> #include <gtk/gtk.h> GtkBuilder *builder; GtkWidget *app; G_MODULE_EXPORT void on_app_destroy (void) { gtk_main_quit (); } G_MODULE_EXPORT void on_menu_quit_activate (void) { gtk_main_quit (); exit(EXIT_SUCCESS); } int main (int argc, char *argv[]) { /* Initialize GTK+ */ g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, (GLogFunc) gtk_false, NULL); gtk_init (&argc, &argv); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING, g_log_default_handler, NULL); builder = gtk_builder_new (); gtk_builder_add_from_file (builder, "tut.glade", NULL); app = GTK_WIDGET (gtk_builder_get_object (builder, "app")); gtk_builder_connect_signals (builder, NULL); g_object_unref (G_OBJECT (builder)); /* Enter the main loop */ gtk_widget_show (app); gtk_main (); return 0; }
joyful file:
<?xml version="1.0"?> <glade-interface> <widget class="GtkWindow" id="window1"> <child> <widget class="GtkFixed" id="fixed1"> <property name="visible">True</property> <child> <widget class="GtkButton" id="button1"> <property name="label" translatable="yes">button</property> <property name="width_request">113</property> <property name="height_request">42</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> </widget> <packing> <property name="x">149</property> <property name="y">69</property> </packing> </child> </widget> </child> </widget> <widget class="GtkWindow" id="window2"> <child> <placeholder/> </child> </widget> </glade-interface>
compilation options:
`pkg-config --cflags --libs gtk+-2.0` -export-dynamic
Linker Settings:
-export-dynamic
My IDE: Code :: Blocks, compiler: GNUC C compiler
How to fix it? Thanks in advance.
source share