I am trying to compile demonstration code on the main page of Vala programming language
int main (string[] args) {
var app = new Gtk.Application(
"com.example.App",
ApplicationFlags.FLAGS_NONE
);
app.activate.connect(() => {
var win = new Gtk.ApplicationWindow(app);
var btn = new Gtk.Button.with_label("Hello World");
btn.click.connect(win.close);
win.child = btn;
win.present();
});
return app.run(args);
}
I am using following command:
$ valac --pkg gtk+-3.0 valademo.vala
However, it is giving following error:
valademo.vala:13.5-13.13: error: The name `click' does not exist in the context of `Gtk.Button'
btn.click.connect(win.close);
^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
Where is the problem and how can it be solved?
That's probably a typo, it should be clicked
not click
. You may want to raise an issue with the website or submit a pull request.
There are a couple of other problems. Firstly GTK+3 needs win.show_all()
, but that has been removed in GTK 4.
Secondly the documentation for win.present()
is advising that function shouldn't be used.
Here's a working example for GTK+3:
int main (string[] args) {
var app = new Gtk.Application(
"com.example.App",
ApplicationFlags.FLAGS_NONE
);
app.activate.connect(() => {
var win = new Gtk.ApplicationWindow(app);
var btn = new Gtk.Button.with_label("Hello World");
btn.clicked.connect(win.close);
win.child = btn;
win.show_all();
});
return app.run(args);
}