G_resources_lookup_data failing

I am practicing programs from gtk4-demo

I am not able to understand g_resources_lookup_data parameters. First one is being explained as
“A pathname inside the resource.”
can some one help me how to pass correct parameter ?

the following is the code I am using :

#include <gtk/gtk.h>

static void css_text_changed( GtkTextBuffer  *buffer, GtkCssProvider *provider )
	GtkTextIter start, end;
	gtk_text_buffer_get_start_iter( buffer, &start );
	gtk_text_buffer_get_end_iter( buffer, &end );
	gtk_text_buffer_remove_all_tags( buffer, &start, &end );
	char *text = gtk_text_buffer_get_text( buffer, &start, &end, FALSE );
	gtk_css_provider_load_from_data( provider, text, -1 );
	g_free( text );

static void apply_css (GtkWidget *widget, GtkStyleProvider *provider)
	GtkWidget *child;

	gtk_style_context_add_provider( gtk_widget_get_style_context( widget ), provider, G_MAXUINT );
	for( child = gtk_widget_get_first_child( widget ); child != NULL; child = gtk_widget_get_next_sibling(child) )
		apply_css( child, provider );

GtkWidget* do_css_basics( GtkWidget *do_widget )
	static GtkWidget *window = NULL;
	if( !window )
		GtkWidget *container, *child;
		GtkStyleProvider *provider;

		window = do_widget;
		gtk_window_set_title (GTK_WINDOW (window), "CSS Basics");
		gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
		g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
		GtkTextBuffer *text = gtk_text_buffer_new( NULL );
		gtk_text_buffer_create_tag( text, "warning", "underline", PANGO_UNDERLINE_SINGLE, NULL );
		gtk_text_buffer_create_tag( text, "error", "underline", PANGO_UNDERLINE_ERROR, NULL );
		provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ());
		container = gtk_scrolled_window_new ();
		gtk_window_set_child (GTK_WINDOW (window), container);
		child = gtk_text_view_new_with_buffer (text);
		gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (container), child);
		g_signal_connect( text, "changed", G_CALLBACK( css_text_changed ), provider );
		GBytes *bytes = g_resources_lookup_data( "/home/lokesh/Desktop/ttk_gui/css_basics.css", 0, NULL );
		gtk_text_buffer_set_text( text, g_bytes_get_data( bytes, NULL ), g_bytes_get_size( bytes ) );
		g_bytes_unref (bytes);
		apply_css( window, provider );
	if (!gtk_widget_get_visible (window))
		gtk_widget_show (window);
		gtk_window_destroy (GTK_WINDOW (window));
	return window;

static void activate( GtkApplication *app, gpointer user_data )
	GtkWidget *window = gtk_application_window_new( app );
	do_css_basics( window );
	gtk_window_destroy( GTK_WINDOW( window ) );
//	gtk_widget_show (window);

int main( int argc, char **argv )
	GtkApplication *app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
	g_signal_connect( app, "activate", G_CALLBACK( activate ), NULL );
	int status = g_application_run( G_APPLICATION( app ), argc, argv);
	g_object_unref( app );
	return status;

Resource paths are not file system paths: they are meant to be used with GResource.

You will need to write a GResource manifest file, and then compile the resources into your own build.

If you used GNOME Builder’s template for GNOME applications, you’d already have a GResource manifest you could extend.

Dear Bassi,

It is first time, I am using builder’s template. I am not able to understand what this manifest file or from where I can extend from. This is from gtk4-demo.
Will you please be able to help me with right file?
Thanks for your help.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.