Calling Object() inside a constructor

Hello,

After looking at some OOP examples of GTK Vala applications I have noticed they are calling Object() inside a class constructor. What is the purpose of this?

namespace MyApp {
	public class Window : Gtk.ApplicationWindow {

		public Window (Application app) {
			Object (
				application: app
			);
		}

		construct {
			title = "This is my new GTK app";
			window_position = Gtk.WindowPosition.CENTER;
			set_default_size(350, 80);

			show_all();
		}

	}
}

Looking at the Valadocs for the ApplicationWindow creation methods it requires an instance of an application.
public ApplicationWindow (Application application)

So what is the call to Object doing here in the class constructor?

Thanks.

This is GObject-style construction, see e.g. https://wiki.gnome.org/Projects/Vala/Tutorial#GObject-Style_Construction in contrast to the “Vala” style construction: https://wiki.gnome.org/Projects/Vala/Tutorial#Construction.

1 Like

Thank you this was extremely useful.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.