How I did find out from my previous question, GObject
style construction is not required for vala class defenition. But much gtk apps use this way when extend base widget. For example, elementary os app center does it for Gtk.ApplicationWindow
class.
So my question is, can I extend any base Gtk
class without using Object()
construction?
Normally you would call the base constructor like:
public class MainWindow : Gtk.ApplicationWindow {
public MainWindow (Gtk.Application application) {
base (application);
}
}
That does not work for classes that themself use GObject style construct parameters.
As you already figured out, the correct way to derive from such a class is:
public class MainWindow : Gtk.ApplicationWindow {
public MainWindow (Gtk.Application application) {
Object (application: application);
}
}
That isn't all too different, except that you have to specify the name of each property and use the Object
class (which is GObject in C) instead of specifying base
.
PS: In my answer to your other question ( How does GObject style construction work? ) what I meant is that you don't need to use GObject style construction when you write your own classes that others can derive from. Here it is the other way around, the design of Gtk.MainWindow forces you to use GObject style construction in your derived class as well.