GtkTemplate only works without Namespace

Please help me. I am trying to add an embedded resource for UI.

I catch an error.

Unknown template TestView' in ui file Resources/UI/TestView.ui’

Works.

[GtkTemplate(ui = "UI/TestView.ui")]
public class TestView : Gtk.ApplicationWindow
{
	public TestView()
	{
			
	}
}

But not working.

namespace Test.MVP.View
{
	[GtkTemplate(ui = "UI/TestView.ui")]
	public class TestView : Gtk.ApplicationWindow
	{
		public TestView()
		{
			
		}
	}
}

Build command

valac {sources} -o Build/Test --pkg gtk4 --gresources=Resources/Resources.xml

Resources/UI/TestView.ui.

<?xml version='1.0' encoding='UTF-8'?>
<interface>
  <requires lib="gtk" version="4.6"/>
  <template class="TestView" parent="GtkApplicationWindow"/>
</interface>

Resources/Resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="">
    <file preprocess="xml-stripblanks">UI/TestView.ui</file>
  </gresource>
</gresources>

The Namespace gets converted into a Prefix, you have to include that in the builder file:

namespace Publishing.GooglePhotos {
[GtkTemplate (ui = "/org/gnome/Shotwell/Publishing/google_photos_publishing_options_pane.ui")]
internal class PublishingOptionsPane : Gtk.Box, Spit.Publishing.DialogPane {
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.0 -->
<interface domain="shotwell">
  <requires lib="gtk+" version="3.14"/>
  <template class="PublishingGooglePhotosPublishingOptionsPane" parent="GtkBox">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
2 Likes

It works! I spent 8 hours on this… Thank you very much!

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