简体   繁体   English

gtk和gtk生成器显示不同的版本

[英]Gtk and gtk builder show different versions

I'm trying to build an helloworld window with Gtk and glade. 我正在尝试使用Gtk和林间空地构建helloworld窗口。 The code compiles fine but on runtime it fails on gtk_builder_add_from_file . 该代码可以正常编译,但在运行时它将在gtk_builder_add_from_file上失败。 The strange thing is that the error reports a current gtk version different to the one I get with gtk_get_major_version/gtk_get_minor_version. 奇怪的是,该错误报告的当前gtk版本与我使用gtk_get_major_version / gtk_get_minor_version获得的版本不同。

GtkBuilder *builder; 
GtkWidget *window;
GError *err = NULL;
gtk_init(NULL,NULL);

printf("maj %d, min %d\n",gtk_get_major_version (),gtk_get_minor_version ());
builder = gtk_builder_new();

gtk_builder_add_from_file (builder, "/path/to/ui.glade", &err);
if (err != NULL)
{
    printf ("%s\n", err->message);
    g_error_free (err);
}

window = GTK_WIDGET(gtk_builder_get_object(builder, "mywin"));

gtk_widget_show(window);
g_object_unref(builder);
gtk_main();
...

Stdout: 标准输出:

maj 3, min 2
/path/to/ui.glade: required gtk+ version 3.2, current version is 2.24

There is no doubt that the glade file was created using Glade 3.x while your application was compiled against Gtk version 2.x. 毫无疑问,根据Gtk版本2.x编译应用程序时,glade文件是使用Glade 3.x创建的。

If you've created the glade file on your computer then chances are that your have both runtime and developer files for Gtk 2 and Gtk 3. 如果您已经在计算机上创建了Glade文件,则很有可能同时拥有Gtk 2和Gtk 3的运行时文件和开发人员文件。

If so, then you must change your compile instructions to link against Gtk 3. For that check you pkg-config instruction and check if it says gtk+-2.0 or gtk+-3.0. 如果是这样,则必须更改编译指令以链接到Gtk3。为此,请检查pkg-config指令,并检查其是否显示gtk + -2.0或gtk + -3.0。 It will most probably say gtk+-2.0, change to gtk+-3.0. 它很可能会说gtk + -2.0,更改为gtk + -3.0。

It also may be possible that you don't have gtk3 dev packages installed, if so, install them. 您可能还没有安装gtk3 dev软件包,如果有,请安装它们。

Glade XML files keep a reference to the minimum gtk version required, changing that may "solve" the issue but it won't work if you use widgets that are only available on gtk 3. Glade XML文件保留了所需的最低gtk版本的引用,此更改可能会“解决”该问题,但是如果您使用仅在gtk 3上可用的小部件,它将无法正常工作。

Another option is to install Glade 2 but is preferable to use the latest Gtk release as others are old. 另一个选择是安装Glade 2,但最好使用最新版本的Gtk,因为其他版本已经过时。

Also check your glade menu, File > Properties and check the required Toolkit version . 还要检查林间空地菜单, 文件>属性,然后检查所需的工具箱版本

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM