• 0
Sign in to follow this  
calmeida

Gtk+ 3: Problemas com GResource para linkar icones e imagens do projeto

Question

Boa tarde a todos,

Estou começando a estudar C com a biblioteca GTK+ 3.0 para criar um CRUD simples, mas estou tendo problemas em exibir os ícones.

se utilizar o caminho físico da imagem funciona, desde que eu rode o executável dentro da própria pasta. Ex.:

...
    // Configuracao de icone no header
    GError *error = NULL;
    tticon = gdk_pixbuf_new_from_file("images/logo.png", &error);
    
    if(!tticon)
    {
		fprintf(stderr, "%s\n", error->message);
		g_error_free(error);
	}
	
	//Atribui o icone a janela
	gtk_window_set_icon(GTK_WINDOW(window), tticon);
...
~/projetos/teste$ ./main

 

Dei uma pesquisada e encontrei o GResource que aparentemente é simples de implementar, mas quando executo apresenta o erro:

 

(main:7644): Gtk-WARNING **: Error loading icon from file 'resource:///br/com/myapp/images/logo.png':
Falha ao abrir o arquivo “resource:///br/com/myapp/images/logo.png”: Arquivo ou diretório não encontrado

 

Segue abaixo o código que implementei:

myapp.gresource.xml

<?xml version="1.0" encoding="UTF-8"?>
<gresources>
  <gresource prefix="/br/com/myapp/">
    <file>images/logo.png</file>
  </gresource>
</gresources>

main.c

#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

void destroy( GtkWidget *widget,gpointer   data )
{
   gtk_main_quit();
}


int main(int argc, char **argv)
{
	GtkWidget *window;
	GdkPixbuf *tticon;

	gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window),"Hello GTK and C");
    

    gtk_window_set_icon_from_file(GTK_WINDOW(window), "resource:///br/com/myapp/images/logo.png", NULL);
    
    
    g_signal_connect (window, "destroy", G_CALLBACK(destroy), NULL);
    gtk_widget_show_all(window);
    gtk_main ();
	return 0;
}

Compilando o gresource e o main.c

glib-compile-resources --target=resources.c --generate-source myapp.gresource.xml
gcc main.c resources.c -o main -lm  `pkg-config gtkmm-3.0 --cflags --libs`
./main
gcc main.c resources.c -o main -lm  `pkg-config gtkmm-3.0 --cflags --libs`

 

Já estou dias tentando descobri o que esta faltando, e nada...

Alguém tem alguma ideia ??

Share this post


Link to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this