I try to load the interface description from the xml file, something does not work out, what is wrong in this case and how will it be correct?

class MyApplication: Gtk.Application { private Gtk.Window window; protected override void activate() { window.show_all(); } protected override void startup() { base.startup(); var builder = new Gtk.Builder(); try { builder.add_from_file("main.ui"); } catch(Error e) { error("Unable to load file: %s", e.message); } this.window = builder.get_object("window") as Gtk.Window; } } public int main(string[] args) { return new MyApplication().run(args); } 

Error starting:

(main: 25258): Gtk-CRITICAL **: gtk_widget_show_all: assertion 'GTK_IS_WIDGET (widget)' failed

main.ui - http://pastebin.com/XaVyDuaH

  • Show your main.ui file. Maybe the problem is in it. - BoSS
  • Added link. - Vitaly Karpenko

1 answer 1

The problem is your ui. You are trying to load a Gtk.Window widget with the window identifier from your file using Gtk.Builder:

 this.window = builder.get_object("window") as Gtk.Window; 

But you did not give the name of your GtkWindow in Glade. Open your main.ui and in the properties on the General tab in the ID field give a name to your widget.

  • It worked, although there is still a problem, why don’t the application shut down immediately after launching the application without errors? (The appearance of the window is not even visible) I did only one label “Hello World” in ui, did not help, an identical example only without the builder from here valadoc.org/ gtk + -3.0 / Gtk.Application.html works fine - Vitaly Karpenko
  • Although no, the window sometimes appears but it is “dead”, it remains after the application is closed and just black in the middle, besides it does not close, well then it does not respond and I receive an offer to close the non-responding window. Here is an example of the ui that I made for the pastebin.com/9Cjkautc test in get_object, I specified the correct window id - Vitaly Karpenko
  • In your example, the main Gtk.main () main event loop does not seem to start. Add this to the activate function after window.show_all () and you will be happy. Unfortunately I can not answer what the catch is, why in the example with Valadoc everything works, but in your case it does not. - BoSS