Newbie gtk4-rs dev trying to figure out how to load gtk4-rs widgets via Cambalache file

Hello everyone!

I’m a newbie to gtk4-rs (and rust itself) trying to figure out how to load gtk4-rs widgets via a Cambalache file. (I’m also a newbie to Cambalache :P, but I’m less intimidated by that since it seems similar enough to Glade, which itself seems to have tutorials I can follow online.)

I found out that if I want to be able to load GUIs using files with GTK 4 (specifically via the gtk4-rs bindings, in my case), I need to use certain functions to do so, but I’m not exactly sure how the surrounding code should be.

The introductory book to gtk4-rs doesn’t seem to cover that. I also checked the file of some FOSS projects online, but they didn’t seem to use the functionality I’m trying to use.

All I think I’ve narrowed it down to is that I need to use one of the following methods of the Builder struct.:
https ://

https ://

https ://

https ://

https ://

https ://

https ://

https ://

So, could someone please show me one way this is done with a small, self-contained example?

Any input would be GREATLY appreciated!

I put a space after https in the links because this website said a new user could only post up to two links, probably because it thinks I’m a spammer.

gtk4-rs/examples/gtk_builder at master · gtk-rs/gtk4-rs · GitHub is a minimal gtk::Builder example that loads the whole window from an .ui file. Is that what you were looking for?

1 Like

Sorry for the late reply! (I was too busy and/or too tired to respond.)

Having said that, thanks! That code and UI file combination works! I think that’s what I need to fully understand what’s going on. I’ll analyze it more in the near future, but I already think I got the gist of it!

For what it’s worth, it doesn’t work with a file I generated from Cambalache (which looks substantially different than the UI file included with that example) (and also Glade, but that was expected since it supposedly doesn’t work with Gtk 4), but it does work with the UI file included with that example.

I don’t know what Cambalache is, but the file format supported by gtk::Builder are only those UI files. Check how Cambalache is supposed to be used with GTK4 :slight_smile:

To generate .ui files from a Cambalache project, you must use the “Export All” option.


Thank you very much! I would probably not have known to search for the “Export All” option if you hadn’t mentioned it.

I’m busy with school now, so I can’t focus on this stuff deeply until I’m done the semester, but I used Cambalache to generate a UI file, and the XML structure looked correct! :smiley:

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