using Gtk;
int main(string[] args) {
Gtk.init(ref args);
var window = new Window();
window.title = "Hello Vala/Gtk";
window.border_width = 10;
window.window_position = WindowPosition.CENTER;
window.set_default_size(350, 70);
window.destroy.connect(Gtk.main_quit);
try {
window.icon = new Gdk.Pixbuf.from_file("images/icon.png");
} catch (Error err) {
stderr.printf("failed to load icon: %s\n", err.message); // Happens on Windows only
}
var button = new Button.with_label("Click me!");
button.clicked.connect(() => {
button.label = "Thank you:-)";
});
window.add(button);
window.show_all();
Gtk.main();
return 0;
}
I have created an images subdir with an icon.png image and an icon.ico image.
I build the app using: valac -o hellogtk --pkg gtk+-3.0 hellogtk.vala which works on both Linux and Windows.
The app runs on both Linux and Windows.
However, on Windows (MSYS2) the error message about the icon is output. I tried changing to the icon.ico but that didn’t help. I can always set the icon using a resource editor but am curious about this platform difference.
The question I’d ask first is what is the error message? There could be multiple reasons why it fails, either related to the platform itself (windows not liking the slash in the path, expecting a backslash instead?) or to the way gtk and its dependencies have been built (MSYS2 not building support for png? I don’t think that would happen but it may)
failed to load icon: CouldnΓÇÖt recognize the image file format for file ΓÇ£images/icon.pngΓÇ¥
As you can see there is an encoding problem in the MSYS2 terminal. I’ve tried various ones but none seem to work.
I got the same problem with an icon.ico file.
Could it be that I need to install additional image-related libraries for Gtk to use?
$ viewport.exe ../hellogtk/images/icon.png
(viewport.exe:3048): Gtk-WARNING **: 11:25:49.875: Could not load a pixbuf from /org/gtk/libgtk/icons/16x16/status/image-missing.png.
This may indicate that pixbuf loaders or the mime database could not be found.
**
Gtk:ERROR:../gtk+-3.24.20/gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)
Bail out! Gtk:ERROR:../gtk+-3.24.20/gtk/gtkiconhelper.c:494:ensure_surface_for_gicon: assertion failed (error == NULL): Failed to load /org/gtk/libgtk/icons/16x16/status/image-missing.png: Unrecognized image file format (gdk-pixbuf-error-quark, 3)
$ iconview.exe
(iconview.exe:2052): Gtk-WARNING **: 11:29:28.250: Could not find the icon 'help-about'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
http://icon-theme.freedesktop.org/releases
**
ERROR:C:/bin/msys64/home/mark/vala/learn/iconview/iconview.vala.c:334:application_construct: code should not be reached
Bail out! ERROR:C:/bin/msys64/home/mark/vala/learn/iconview/iconview.vala.c:334:application_construct: code should not be reached
Here’re the packages I’ve installed in MSYS2:
$ pacman -Qe
base 2020.05-2
filesystem 2020.02-5
mingw-w64-x86_64-gcc 10.1.0-3
mingw-w64-x86_64-gtk3 3.24.20-3
mingw-w64-x86_64-libgee 0.20.3-1
mingw-w64-x86_64-pkg-config 0.29.2-1
mingw-w64-x86_64-vala 0.48.7-1
vim 8.2.0869-1
I then ran gdk-pixbuf-query-loaders --update-cache as suggested.
Unfortunately this didn’t help: I still get the same problems. hellogtk runs but produces the error output, and viewport and iconview both give the same error messages as before.