RE: Invalid UTF-8 string passed to pango_layout_set_text()
- From: "Liu, Raymond" <raymond liu intel com>
- To: Randy <randyqiuxy hotmail com>, gtk-list <gtk-list gnome org>
- Subject: RE: Invalid UTF-8 string passed to pango_layout_set_text()
- Date: Fri, 25 Dec 2009 16:49:18 +0800
>I'm learning GTK+ using "Foundations of GTK+ Development" by Andrew Krause and >today I did the exercise2-1(chapter2) which should meet the demand as follows:
>when press the key,the label's text and window's title can interchange.
>However,I got the warning:"Invalid UTF-8 string passed to pango_layout_set_text()".
>The label's text will be messy character when I first press SHIFT and both become >messy when I press key at the second time.
>The code is as follows and please note my comments:
>static gboolean changeTitle(GtkWidget* window,
> GdkEventKey* keyEvent,
> GtkLabel *label)
>const gchar *textLabel=gtk_label_get_text(GTK_LABEL(label));
>const gchar *textWindow=gtk_window_get_title(GTK_WINDOW(window));
As you can see here, these gchar* are owned by the label/window, and upon you setting the window title, the textWindow point to something might already been freed, so cause these strange problem.
You need something like
gchar *textWindow= g_strdup(gtk_window_get_title(GTK_WINDOW(window)));
to store the tmp string data, and free it after you done with gtk_label_set_text in your code below
> //surprise,if I skip(via "//") one of the two lines, another
> //will work fine.....
>Thanks for any clue!
] [Thread Prev