Gtk_button_get_label

Hi! Im new

static gboolean update_text (GtkWidget **buttons) {
	static int i = 11;
        const gchar *text =  gtk_button_get_label (GTK_BUTTON (buttons[i]));
        puts(text);
	gtk_button_set_label (GTK_BUTTON (buttons[i]), "FA1");
       sleep(1);
	gtk_button_set_label (GTK_BUTTON (buttons[i]), text);
	--i;
	if (i < 0)
		return FALSE;
	return TRUE

This is my code which i run with g_timeout_add_seconds, but instead of change the label of the buttons in a vertical box to “FA1” for one second and then the original label I gett errors like:

Pango-Warning: invalid utf-8 string passed to pango_layout.

The puts prints the old labels.

Hm! what im making wrong?


gtk_button_get_label() doesn’t make a copy of the button’s label text,
so when you change if to “FA1”, the pointer you stored in text is not
valid anymore.

You need to make a copy of the button’s label text (e.g. g_strdup()),
and then you can reuse it safely later. Don’t forget to free it when
done with it.

1 Like

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