【问题标题】:How to include resources file in anjuta project如何在 anjuta 项目中包含资源文件
【发布时间】:2014-10-08 20:28:22
【问题描述】:

我正在尝试更新 vala 中的图形项目,将大量代码行移动到 ui 文件中。 我想使用模板(可用于 glib-2.38 和 GTK+3.8,类似的东西)。

我的项目是用 Anjuta 和 autoconf 管理的。

src目录中有

application.ui:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.8 -->
  <template class="SpiWindow" parent="GtkApplicationWindow">
    <property name="title" translatable="yes">Example Application</property>
    <property name="default-width">600</property>
    <property name="default-height">400</property>
    <child>
        <placeholder />
    </child>
  </template>
</interface>

resources.xml:

<?xml version="1.0" charset="UTF-8" ?>
<gresources>
  <gresource prefix="/org/app/spi">
    <file compressed="true" preprocess="xml-stripblanks">application.ui</file>
  </gresource>
</gresources>

src/Makefile.am 中,我已将--gresources resources.xml 附加到spi_VALAFLAGS。最后我像这样声明了Gtk.ApplicationWindow

[GtkTemplate(ui = "/org/app/spi/application.ui")]
internal class SpiWindow : Gtk.ApplicationWindow {

    // Constructor
    public Window (Gtk.Application application) {
        Object(application: application);
    }
}

但是当我编译然后运行应用程序时,会出现错误消息:

(spi:9749): Gtk-CRITICAL : Unable to load resource for composite template for type 'SpiWindow': The resource at '/org/app/spi/application.ui' does not exist
(spi:9749): Gtk-CRITICAL : gtk_widget_init_template: assertion 'template != NULL' failed

【问题讨论】:

    标签: gtk3 vala anjuta


    【解决方案1】:

    您仍然需要编译资源并包含它们:

    GLIB_COMPILE_RESOURCES=glib-compile-resources
    
    resources.c: resources.xml $(shell $(GLIB_COMPILE_RESOURCES) --generate-dependencies resources.xml)
      $(GLIB_COMPILE_RESOURCES) --target=$@  --generate-source $<
    

    并将resources.c 作为源文件包含在spi_SOURCES 中。

    【讨论】:

    • 谢谢,我尝试使用 baobab makefile 作为模式,但我错过了应将构建的 C 文件添加到 spi_SOURCES 的部分。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    相关资源
    最近更新 更多