[Vala] Problem using the Gtk.Buildable iface



I've just started to experiment with making my widgets implement the
Gtk.Buildable interface. I have however stumbled upon some strange
issues. When loading the builder definition file I get an error that
my custom class does not exist even though I've named it correctly in
the xml file (NamespaceClassname). This can be fixed by instantiating
the class one time before GtkBuilder parses the ui definition. So it
seems like there is some type registration going on when instantiating
an object the first time, this is all pretty confusing and I really
hope I'm doing something wrong here and hope someone on the list can
clear things up for me. Here's a minimal test case:

namespace Foo {
 public class Bar : Gtk.Window, Gtk.Buildable {
  public static int main (string[] args) {
   Gtk.init(ref args);

   // NEVER USED BUT NEEDED FOR GtkBuilder TO NOT RAISE EXCEPTION
   var test = new Foo.Bar();

   var builder = new Gtk.Builder ();
   var desc = "<?xml version=\"1.0\"?><interface><object
class=\"FooBar\" id=\"window\"><property
name=\"title\">mytesttitle</property></object></interface>";

   try {
    builder.add_from_string(desc, desc.length);
   } catch (GLib.Error e) {
        GLib.error(e.message);
   }

   var window = builder.get_object("window") as Foo.Bar;
   window.show();

   Gtk.main();

   return 0;
  }
 }
}

When executing the code a window will pop up with the "mytesttitle" as
title, so it really is the window created from the ui definition, and
if the "var test ..." line is commented out the application will exit
with the following error message:

** ERROR **: Invalid object type `FooBar'

This might be a bug in Vala, GTK, or simply (and hopefully!) me not
doing it right.

-- 
Daniel Svensson



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]