【问题标题】:Unable to load resource for composite template无法为复合模板加载资源
【发布时间】:2017-03-28 09:15:10
【问题描述】:

我有一个用 Vala 编写的非常基本的 GTK 应用程序(非工作源代码树 here),它打算从 GResource 加载主应用程序窗口的资源。

所以我创建了一个资源文件,用glib-compile-resources 编译它,并将它作为--gresources=$(top_srcdir)/data/gauthenticator.gresource.xml 添加到VALAFLAGS

数据文件的相关部分如下所示:

<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 存储库中复制了大多数与资源相关的行,但显然遗漏了一些内容。

【问题讨论】:

    标签: gtk3 vala


    【解决方案1】:

    您如何使用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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-08-08
      • 1970-01-01
      • 2014-03-26
      • 2019-07-13
      • 2017-05-02
      • 2017-12-11
      • 1970-01-01
      相关资源
      最近更新 更多