Cant load .ui file in vala


I use builder flatpak version to play with Gtk+ with vala

in /src directory I have main.vala and main.ui also resources and meson files, main.vala is embed in meson with code

rush_sources = [

and main.ui embed in resources file with code

  <gresource prefix="/me/rush/Rush">

and this code of main.ui

finally I imported main.ui in my code

        var build = new Gtk.Builder ();
        build.add_from_file ("/src/main.ui");

I tried diffrent paths and no one load the file, code give me no such file or directory.

If any one can help please

I edited previous UI to replace template with object as


and I edited code of import file to

build.add_from_resource ("/me/rush/Rush/main.ui");

compiling done without errors but there are warnings in compiling and running time

after that interface doesnt show, I tried

window.show_all ();

but it tell me window does not have show_all method coz window is Glib object

Gtk.Builder.get_object() returns a GLib.Object, so you need to explicitly cast it to the correct type (a Gtk.ApplicationWindow in this case).

Also, please use code blocks instead of screenshots :wink:

1 Like

Thank you
I tried this as

var window =  (Gtk.ApplicationWindow) Gtk.Builder.get_object ("window");
window.show_all ();

and no compiling errors or warnings, but still no thing show in screen

I have this output in running time

Application started at +03 05:20:30 م

(rush:3): dbind-WARNING **: 17:20:30.762: AT-SPI: Error retrieving accessibility bus address: org.freedesktop.DBus.Error.ServiceUnknown: org.freedesktop.DBus.Error.ServiceUnknown
(rush:3): GVFS-RemoteVolumeMonitor-DEBUG: 17:20:30.768: Error: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: org.freedesktop.DBus.Error.ServiceUnknown

(rush:3): GVFS-DEBUG: 17:20:30.769: cannot open directory /usr/share/gvfs/remote-volume-monitors: Error opening directory “/usr/share/gvfs/remote-volume-monitors”: No such file or directory
(rush:3): GVFS-DEBUG: 17:20:30.774: org.gtk.vfs.MountTracker.listMountableInfo call failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: org.freedesktop.DBus.Error.ServiceUnknown (g-dbus-error-quark, 2)

(rush:3): GLib-GIO-DEBUG: 17:20:30.774: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ‘gio-vfs’
Application exited

You should set window's “application” property to your app :wink:

  // inside your activate callback 
  var window = (Gtk.ApplicationWindow) build.get_object ("window");
  window.application = app;
1 Like

thank you a lot, this work great :star_struck:

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