我最近将Fedora 20更新到Fedora 21,并且在更新后我在GTK3中加载图像时遇到了问题。
我尝试过以下示例代码:
#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
int main(int argc, char *argv[])
{
GtkWidget *window, *image;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 1024, 768);
gtk_window_set_title(GTK_WINDOW(window), "Image");
gtk_window_set_resizable(GTK_WINDOW(window), TRUE);
gtk_container_set_border_width(GTK_CONTAINER(window), 2);
image = gtk_image_new_from_file("/home/mbucko/image.jpg");
gtk_container_add(GTK_CONTAINER(window), image);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
当调用函数gtk_image_new_from_file时,我得到以下打印输出:
(runtime:23246): Gtk-WARNING **: Could not find the icon 'image-missing-ltr'. The 'hicolor' theme
was not found either, perhaps you need to install it.
You can get a copy from:
http://icon-theme.freedesktop.org/releases
(runtime:23246): Gtk-WARNING **: Error loading theme icon 'image-missing' for stock: Icon 'image-missing' not present in theme
(runtime:23246): Gtk-WARNING **: Error loading theme icon 'image-missing' for stock: Icon 'image-missing' not present in theme
(runtime:23246): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
然后会显示一个没有图像的窗口。
我安装了hicolor-icon-theme-0.14-1和gnome-icon-theme-devel-3.12。
Gtk是3.14.8。
还尝试了jpg,tiff和png文件。
有谁知道可能出现什么问题?
编辑: 刚刚发现,当我从bash运行应用程序时,它可以工作。我只有在从Eclipse运行时才会遇到这个问题。