无法加载复合模板的资源
Unable to load resource for composite template
我有一个用 Vala 编写的非常基本的 GTK 应用程序(非工作源代码树 here),它打算从 GResource 加载主应用程序 window 的资源。
所以我创建了一个资源文件,用 glib-compile-resources
编译它,并将它添加到 VALAFLAGS
作为 --gresources=$(top_srcdir)/data/gauthenticator.gresource.xml
。
数据文件的相关部分如下所示:
<gresource prefix="/eu/polonkai/gergely/gauthenticator">
<file preprocess="xml-stripblanks">gauth-window.ui</file>
</gresource>
我是这样使用它的:
[GtkTemplate (ui = "/eu/polonkai/gergely/gauthenticator/gauth-window.ui")]
class Window : Gtk.ApplicationWindow {
[GtkChild]
private Gtk.ProgressBar countdown;
}
我Makefile.am
的相关部分:
gresource_file = $(top_srcdir)/data/gauthenticator.gresource.xml
gauthenticator_VALAFLAGS = --pkg gtk+-3.0 --target-glib=2.38 --gresources $(gresource_file)
编译期间一切正常,但在运行时出现此错误:
(gauthenticator:16501): Gtk-CRITICAL **: Unable to load resource for composite template for type 'GAuthenticatorWindow': The resource at '/eu/polonkai/gergely/gauthenticator/gauth-window.ui' does not exist
(gauthenticator:16501): Gtk-CRITICAL **: gtk_widget_class_bind_template_child_full: assertion 'widget_class->priv->template != NULL' failed
(gauthenticator:16501): Gtk-CRITICAL **: gtk_widget_init_template: assertion 'template != NULL' failed
我从 GNOME Boxes 存储库中复制了大部分与资源相关的行,但显然遗漏了一些内容。
您如何使用 glib-compile-resources
编译资源?我建议将其编译为 C 文件:
glib-compile-resources --sourcedir data --generate-source --target my_build_dir/resources/resources.c data/gauthenticator.gresource.xml
然后将 my_build_dir/resources/resources.c
添加到您的 _SOURCES
以便它与您的 Vala 源代码一起编译。 valac
的 --gresources
选项仅对 Vala 的 GTK+ 复合模板支持进行类型检查。
我没有尝试将 GResource C 文件编译为 Vala 到 C 然后 C 到二进制编译过程的一部分。目前看来您只是在整个编译过程中使用 valac
。
我有一个用 Vala 编写的非常基本的 GTK 应用程序(非工作源代码树 here),它打算从 GResource 加载主应用程序 window 的资源。
所以我创建了一个资源文件,用 glib-compile-resources
编译它,并将它添加到 VALAFLAGS
作为 --gresources=$(top_srcdir)/data/gauthenticator.gresource.xml
。
数据文件的相关部分如下所示:
<gresource prefix="/eu/polonkai/gergely/gauthenticator">
<file preprocess="xml-stripblanks">gauth-window.ui</file>
</gresource>
我是这样使用它的:
[GtkTemplate (ui = "/eu/polonkai/gergely/gauthenticator/gauth-window.ui")]
class Window : Gtk.ApplicationWindow {
[GtkChild]
private Gtk.ProgressBar countdown;
}
我Makefile.am
的相关部分:
gresource_file = $(top_srcdir)/data/gauthenticator.gresource.xml
gauthenticator_VALAFLAGS = --pkg gtk+-3.0 --target-glib=2.38 --gresources $(gresource_file)
编译期间一切正常,但在运行时出现此错误:
(gauthenticator:16501): Gtk-CRITICAL **: Unable to load resource for composite template for type 'GAuthenticatorWindow': The resource at '/eu/polonkai/gergely/gauthenticator/gauth-window.ui' does not exist
(gauthenticator:16501): Gtk-CRITICAL **: gtk_widget_class_bind_template_child_full: assertion 'widget_class->priv->template != NULL' failed
(gauthenticator:16501): Gtk-CRITICAL **: gtk_widget_init_template: assertion 'template != NULL' failed
我从 GNOME Boxes 存储库中复制了大部分与资源相关的行,但显然遗漏了一些内容。
您如何使用 glib-compile-resources
编译资源?我建议将其编译为 C 文件:
glib-compile-resources --sourcedir data --generate-source --target my_build_dir/resources/resources.c data/gauthenticator.gresource.xml
然后将 my_build_dir/resources/resources.c
添加到您的 _SOURCES
以便它与您的 Vala 源代码一起编译。 valac
的 --gresources
选项仅对 Vala 的 GTK+ 复合模板支持进行类型检查。
我没有尝试将 GResource C 文件编译为 Vala 到 C 然后 C 到二进制编译过程的一部分。目前看来您只是在整个编译过程中使用 valac
。