linux - Gtk+3 &C & Glade problems -


i tried make simple gui program c , glade on linux. wrote simple program , design window glade. when run code says:

(gtk-test:23026): gtk-critical **: gtk_widget_show: assertion ‘gtk_is_widget(widget)’ failed 

and no window open. searched bit on internet cant helpful. have convert glade file .xml didn't work.

c

#include <gtk/gtk.h>  int main(int argc, char *argv[]) {     gtkbuilder      *builder;      gtkwidget       *window;      gtk_init(&argc, &argv);      builder = gtk_builder_new();     gtk_builder_add_from_file (builder, "window_main.glade", null);      window = gtk_widget(gtk_builder_get_object(builder, "window_main"));     gtk_builder_connect_signals(builder, null);      g_object_unref(builder);      gtk_widget_show(window);                     gtk_main();      return 0; }  void on_window_main_destroy() {     gtk_main_quit(); } 

glade

<?xml version=1.0 encoding="uft-8"?> <!-- generated glade 3.18.3 --> <interface>     <requires lib="gtk+" version="3.12"/>     <object class="gtkwindow" id="window_main">         <property name="can_focus">false</property>         <property name="title" translatable="yes">test window</property>         <property name="default_width">640</property>         <property name="default_height">480</property>         <signal name="destroy" handler="on_window_main_destroy" swapped="no"/>         <child>             <placeholder/>         </child>     </object> </interface> 

it seems add xml tag hand , it's malformed. @ same time not doing error checking gtk_builder_add_from_file function.

your xml starts with:

<?xml version=1.0 encoding=uft-8> 

and should be:

<?xml version="1.0" encoding="utf-8"?> 

to avoid situation should use gerror , check if there errors when parsing builder file gtk_builder_add_from_file.

edit:

i saw have updated glade file in question. if answer may not obvious. anyway, here code error checking glade file existence , @underscore_d tip on checking gtkbuilder get_object function (could use g_assert macro instead):

#include <gtk/gtk.h>  int main(int argc, char *argv[]) {     gerror          *err = null;     gtkbuilder      *builder;      gtkwidget       *window;      gtk_init(&argc, &argv);      builder = gtk_builder_new();     gtk_builder_add_from_file (builder, "window_main.glade", &err);      if (err != null) {         fprintf (stderr, "unable read file: %s\n", err->message);         g_error_free(err);         return 1;     }      window = gtk_widget(gtk_builder_get_object(builder, "window_main"));      if (window == null || !gtk_is_window(window)) {         fprintf (stderr, "unable window. (window == null || window != gtkwindow)\n");         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(); } 

compile with:

gcc -rdynamic -o window main.c `pkg-config --cflags --libs gtk+-3.0` 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -